JanfNavf/Character-Style_Chatbot
0
1import gradio as gr2from app import get_answer, get_character_prompt, get_characters3 4 5with gr.Blocks() as demo:6 character_dropdown = gr.Dropdown(label="Character Selection", value="William Shakespeare", choices=get_characters())7 chatbot = gr.Chatbot(get_character_prompt("William Shakespeare"), type="messages")8 9 msg = gr.Textbox()10 clear = gr.ClearButton([msg, chatbot])11 12 def respond(message, chat_history):13 chat_history.append({"role": "user", "content": message})14 response = get_answer(chat_history)15 chat_history.append({"role": "assistant", "content": response})16 return "", chat_history17 18 msg.submit(respond, [msg, chatbot], [msg, chatbot])19 character_dropdown.input(get_character_prompt, inputs=[character_dropdown], outputs=[chatbot])20 21if __name__ == "__main__":22 demo.launch(server_name="0.0.0.0", server_port=7860)23 