shahin-hashim commited on
Commit
3e86914
1 Parent(s): 4638251

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import gradio as gr
3
+
4
+ responses = {
5
+ " ": "Oops! Did you just unleash the invisible ink message? Looks like you're communicating in stealth mode!",
6
+ "greeting": ["Hello!", "Hi there!", "Greetings!"],
7
+ "how are you": "I'm good, thank you! How are you?",
8
+ "what is your name": "I'm a chatbot. You can call me Hugo!",
9
+ "age": "I don't have an age as I am just a chatbot!",
10
+ "good": "That's great!",
11
+ "bye": "Goodbye! Have a great day!",
12
+ "weather": "Let me check the weather forecast. Where would you like to know about?",
13
+ "favorite color": "I don't have the ability to see colors, but I like all shades of blue!",
14
+ "tell me a joke": "Why don't scientists trust atoms? Because they make up everything!",
15
+ "who created you": "I was created by one of the 100xEngineers' students!",
16
+ "what do you do": "I'm here to chat with you and answer your questions!",
17
+ "where are you from": "I exist in the digital realm, so I don't have a physical location!",
18
+ "what languages do you speak": "I can understand and respond in English languages",
19
+ "tell me a fun fact": "Did you know that honey never spoils? Archaeologists have found pots of honey in ancient "
20
+ "Egyptian tombs that are over 3000 years old and still perfectly edible!",
21
+ "do you have siblings": "No, I'm an only child, but I have many fellow chatbot companions from 100xEngineers Club!",
22
+ "mystery": ["Aah! I'm dodging this question like it's a game of dodge ball, but hey, you've piqued my interest "
23
+ "with this curiosity bomb!", "My wit's currently on a coffee break. Let's catch up later when it's "
24
+ "back from its caffeine fix!", "Interest and humour taking a rain check, "
25
+ "but still, intriguing question!"],
26
+ }
27
+
28
+
29
+ def get_greeting():
30
+ return random.choice(responses["greeting"])
31
+
32
+
33
+ def get_mystery():
34
+ return random.choice(responses["mystery"])
35
+
36
+
37
+ def send_text(message, history):
38
+ # print("Message-", message)
39
+ message = message.lower()
40
+
41
+ if message in responses:
42
+ return responses[message]
43
+ elif message.startswith("hello") or message.startswith("hi"):
44
+ return get_greeting()
45
+ elif message.endswith("?"):
46
+ return get_mystery()
47
+ elif "weather" in message:
48
+ return responses["weather"]
49
+ elif "good" in message:
50
+ return responses["good"]
51
+ else:
52
+ return "I'm still under development and learning. Could you rephrase or try a different question?"
53
+
54
+
55
+ chat = gr.ChatInterface(
56
+ fn=send_text,
57
+ chatbot=gr.Chatbot(height=300, bubble_full_width=False),
58
+ textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
59
+ # message_history=[], # Optional: Store chat history if desired
60
+ title="Hey hey, it's Hugo!",
61
+ theme="soft",
62
+ examples=["Hello", "Am I cool?", "Are tomatoes vegetables?", "Who created you"],
63
+ cache_examples=True,
64
+ retry_btn=None,
65
+ undo_btn=None,
66
+ description="Ready to rock this day with a grin as wide as a banana peel?",
67
+ )
68
+
69
+
70
+ def show_response(response):
71
+ chat.append(response)
72
+
73
+
74
+ chat.launch()