import gradio as gr
def converse(message, history, character):
print("User message:", message)
print("Chat history:", history)
print("Selected character:", character)
# Your chatbot logic here
response = f"You said: {message}. You're talking to {character}."
return response
def reset(character):
return [], []
# Gradio app
with gr.Blocks() as demo:
gr.Markdown(f"
{'My Chatbot'}
")
bot = gr.Chatbot(render=False)
dropdown = gr.Dropdown(
["Character 1", "Character 2", "Character 3", "Character 4", "Character 5", "Character 6", "Character 7", "Character 8", "Character 9", "Character 10", "Character 11", "Character 12", "Character 13"],
label="Characters",
info="Select the character that you'd like to speak to",
value="Character 1"
)
chat = gr.ChatInterface(
fn=converse,
chatbot=bot,
additional_inputs=dropdown
)
dropdown.change(fn=reset, inputs=dropdown, outputs=[bot, chat.chatbot_state])
demo.queue()
demo.launch()