Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Define a list of Magic 8 Ball responses
|
| 5 |
+
responses = [
|
| 6 |
+
"Without a doubt.",
|
| 7 |
+
"Ask again later.",
|
| 8 |
+
"Outlook not so good.",
|
| 9 |
+
"Yes – definitely!",
|
| 10 |
+
"Better not tell you now.",
|
| 11 |
+
"My sources say no.",
|
| 12 |
+
"Signs point to yes.",
|
| 13 |
+
"Cannot predict now.",
|
| 14 |
+
"Absolutely not.",
|
| 15 |
+
"Most likely.",
|
| 16 |
+
]
|
| 17 |
|
| 18 |
+
# Define the response function
|
| 19 |
+
def magic_8_ball(question):
|
| 20 |
+
if question.strip() == "":
|
| 21 |
+
return "Please ask a yes/no question!"
|
| 22 |
+
return random.choice(responses)
|
| 23 |
|
| 24 |
+
# Create the Gradio interface
|
| 25 |
+
chatbot = gr.Interface(
|
| 26 |
+
fn=magic_8_ball,
|
| 27 |
+
inputs=gr.Textbox(label="Ask the Magic 8 Ball a Yes/No Question:"),
|
| 28 |
+
outputs=gr.Textbox(label="Magic 8 Ball says..."),
|
| 29 |
+
title="Magic 8 Ball Chatbot",
|
| 30 |
+
description="Ask a yes/no question and reveal your fate!"
|
| 31 |
+
)
|
| 32 |
|
| 33 |
+
# Launch the app
|
| 34 |
+
chatbot.launch()
|