File size: 4,399 Bytes
8226dd3
 
 
 
d96f22d
8226dd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import random
import gradio as gr
import requests

URL = "https://shahin-hashim-hugo-fast-api.hf.space"

responses = {
    " ": "Oops! Did you just unleash the invisible ink message? Looks like you're communicating in stealth mode! 😄",
    "greeting": ["Hello!", "Hi there!", "Greetings!"],
    "how are you": "I'm good, thank you! How are you?",
    "what is your name": "I'm a chatbot. You can call me Hugo!",
    "age": "I don't have an age as I am just a chatbot!",
    "good": "That's great!",
    "bye": "Goodbye! Have a great day!",
    "weather": "Let me check the weather forecast. Where would you like to know about?",
    "favorite color": "I don't have the ability to see colors, but I like all shades of blue!",
    "tell me a joke": "Why don't scientists trust atoms? Because they make up everything!",
    "who created you": "I was created by one of the 100xEngineers' students!",
    "what do you do": "I'm here to chat with you and answer your questions!",
    "where are you from": "I exist in the digital realm, so I don't have a physical location!",
    "what languages do you speak": "I can understand and respond in English languages",
    "tell me a fun fact": "Did you know that honey never spoils? Archaeologists have found pots of honey in ancient "
                          "Egyptian tombs that are over 3000 years old and still perfectly edible!",
    "do you have siblings": "No, I'm an only child, but I have many fellow chatbot companions from 100xEngineers Club!",
    "mystery": ["Aah! I'm dodging this question like it's a game of dodge ball, but hey, you've piqued my interest "
                "with this curiosity bomb!", "My wit's currently on a coffee break. Let's catch up later when it's "
                                             "back from its caffeine fix!", "Interest and humour taking a rain check, "
                                                                            "but still, intriguing question!"],
}


def get_greeting():
    return random.choice(responses["greeting"])


def get_mystery():
    return random.choice(responses["mystery"])


def get_dog_facts():
    response = requests.get(f"{URL}/dogfacts")
    data = response.json()
    # print("data-", data["message"])
    return data["message"]


def get_anime_quotes():
    response = requests.get(f"{URL}/animequotes")
    data = response.json()
    # print("data-", data["message"])
    return data["message"]


def get_boredom_act():
    # print("enter")
    response = requests.get(f"{URL}/boredomact")
    data = response.json()
    # print("data-", data["message"])
    return data["message"]


def get_word_meaning(word):
    # print("word-enter-", word)
    response = requests.post(f"{URL}/wordmeaning", json={"text": word})
    data = response.json()
    # print("data-", data["message"])
    return data["message"]


def send_text(message, history):
    # print("Message-", message)
    message = message.lower()

    if message in responses:
        return responses[message]
    elif message.startswith("hello") or message.startswith("hi"):
        return get_greeting()
    elif message.endswith("?"):
        return get_mystery()
    elif "weather" in message:
        return responses["weather"]
    elif "good" in message:
        return responses["good"]
    # API HUGO V2
    elif "dog facts" in message:
        return get_dog_facts()
    elif "anime quotes" in message:
        return get_anime_quotes()
    elif "bored" in message:
        return get_boredom_act()
    elif "meaning" in message:
        word = message.replace(" meaning", "")
        # print("word-", word)
        return get_word_meaning(word)
    else:
        return "I'm still under development and learning. Could you rephrase or try a different question?"


chat = gr.ChatInterface(
    fn=send_text,
    chatbot=gr.Chatbot(height=300, bubble_full_width=False),
    textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
    # message_history=[],  # Optional: Store chat history if desired
    title="Hey hey, it's Hugo!",
    theme="soft",
    examples=["Hello", "Am I cool?", "Are tomatoes vegetables?", "Who created you"],
    cache_examples=True,
    retry_btn=None,
    undo_btn=None,
    description="Ready to rock this day with a grin as wide as a banana peel?",
)


def show_response(response):
    chat.append(response)


chat.launch()