jfelipenc commited on
Commit
cf2e514
โ€ข
1 Parent(s): 776e31f

Chat Interfaces

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import time
3
+ import gradio as gr
4
+
5
+ def placeholder(input, history):
6
+ return "You typed: " + input
7
+
8
+ class ChatbotInterface():
9
+ def __init__(self, name):
10
+ self.name = name
11
+ self.chatbot = gr.Chatbot()
12
+ self.chat_history = []
13
+
14
+ with gr.Row() as row:
15
+ row.justify = "end"
16
+ self.msg = gr.Textbox(scale=7)
17
+ self.submit = gr.Button("Submit", scale=1)
18
+
19
+ clear = gr.ClearButton([self.msg, self.chatbot])
20
+ chat_history = []
21
+
22
+ self.submit.click(self.respond, [self.msg, self.chatbot], [self.msg, self.chatbot])
23
+
24
+ def respond(self, msg, history):
25
+ 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?"])
26
+ self.chat_history.append([msg, bot_message])
27
+ time.sleep(1)
28
+ return "", self.chat_history
29
+
30
+ if __name__ == "__main__":
31
+ with gr.Blocks() as demo:
32
+ with gr.Row() as intro:
33
+ gr.Markdown(
34
+ """
35
+ ## MedChat
36
+ Welcome to MedChat, a medical assistant chatbot! You can currently chat with three chatbots that are trained on the same medical dataset.
37
+
38
+ If you want to compare the output of each model, click the submit to all button and see the magic happen!
39
+ """
40
+ )
41
+ with gr.Row() as row:
42
+ with gr.Column() as col1:
43
+ with gr.Tab("GaiaMinimed") as gaia:
44
+ gaia_bot = ChatbotInterface("GaiaMinimed")
45
+ with gr.Column() as col2:
46
+ with gr.Tab("MistralMed") as mistral:
47
+ mistral_bot = ChatbotInterface("MistralMed")
48
+ with gr.Tab("Falcon-7B") as falcon7b:
49
+ falcon_bot = ChatbotInterface("Falcon-7B")
50
+
51
+
52
+ def submit_to_all(value):
53
+ for element in [gaia_bot, mistral_bot, falcon_bot]:
54
+ element.msg.value = value
55
+ element.submit.click()
56
+
57
+ submit_all = gr.Button("Submit to All", scale=1)
58
+ submit_all.click(submit_to_all, [gaia_bot.msg])
59
+
60
+ demo.launch()