Spaces:
Sleeping
Sleeping
import random | |
import gradio as gr | |
import requests | |
URL = "http://localhost:8000" | |
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() | |