Tafar commited on
Commit
c5e443c
·
1 Parent(s): 513d27b

Create chat_app.py

Browse files
Files changed (1) hide show
  1. chat_app.py +43 -0
chat_app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ import time
4
+
5
+ def respond(message, chat_history):
6
+ user_input = message.lower()
7
+
8
+ # Topic-based responses
9
+ if "technology" in user_input:
10
+ bot_message = "Sure, let's talk about technology. What specific aspect are you interested in?"
11
+
12
+ elif "science" in user_input:
13
+ bot_message = "Science is fascinating! What scientific topic would you like to discuss?"
14
+
15
+ elif "healthcare" in user_input:
16
+ bot_message = "Healthcare is crucial. How can I assist you in the healthcare domain?"
17
+
18
+ elif "education" in user_input:
19
+ bot_message = "Education is important. What educational topic are you curious about?"
20
+
21
+ elif "sports" in user_input:
22
+ bot_message = "Sports are exciting! What sport or team are you a fan of?"
23
+
24
+ else:
25
+ bot_message = "Welcome! I'm Glo AI. How can I assist you today?"
26
+
27
+ chat_history.append(bot_message)
28
+ time.sleep(2) # Simulating a brief delay for a more natural conversation
29
+ return "", chat_history[-chat_history_slider.value:]
30
+
31
+ def launch_chat_app():
32
+ with gr.Blocks() as demo:
33
+ chatbot = gr.Chatbot()
34
+ msg = gr.Textbox("Write your input here")
35
+ submit_button = gr.Button("Submit")
36
+ chat_history_slider = gr.Slider(maximum=10, default=5, label="Chat History Length")
37
+
38
+ submit_button.click(respond, [msg, chatbot])
39
+
40
+ demo.launch()
41
+
42
+ if __name__ == "__main__":
43
+ launch_chat_app()