import random import time import gradio as gr def placeholder(input, history): return "You typed: " + input class ChatbotInterface(): def __init__(self, name): self.name = name self.chatbot = gr.Chatbot() self.chat_history = [] with gr.Row() as row: row.justify = "end" self.msg = gr.Textbox(scale=7) self.submit = gr.Button("Submit", scale=1) clear = gr.ClearButton([self.msg, self.chatbot]) chat_history = [] self.submit.click(self.respond, [self.msg, self.chatbot], [self.msg, self.chatbot]) def respond(self, msg, history): bot_message = random.choice(["Hello, I'm MedChat! How can I help you?", "Hello there! I'm Medchat, a medical assistant! How can I help you?"]) self.chat_history.append([msg, bot_message]) time.sleep(1) return "", self.chat_history if __name__ == "__main__": with gr.Blocks() as demo: with gr.Row() as intro: gr.Markdown( """ ## MedChat Welcome to MedChat, a medical assistant chatbot! You can currently chat with three chatbots that are trained on the same medical dataset. If you want to compare the output of each model, click the submit to all button and see the magic happen! """ ) with gr.Row() as row: with gr.Column() as col1: with gr.Tab("GaiaMinimed") as gaia: gaia_bot = ChatbotInterface("GaiaMinimed") with gr.Column() as col2: with gr.Tab("MistralMed") as mistral: mistral_bot = ChatbotInterface("MistralMed") with gr.Tab("Falcon-7B") as falcon7b: falcon_bot = ChatbotInterface("Falcon-7B") def submit_to_all(value): for element in [gaia_bot, mistral_bot, falcon_bot]: element.msg.value = value element.submit.click() submit_all = gr.Button("Submit to All", scale=1) submit_all.click(submit_to_all, [gaia_bot.msg]) demo.launch()