Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
def chat(message, history):
|
| 5 |
+
history = history or []
|
| 6 |
+
message_lower = message.lower()
|
| 7 |
+
|
| 8 |
+
if "hello" in message_lower or "hi" in message_lower:
|
| 9 |
+
response = random.choice(["Hello! How can I help you?", "Hi there!", "Hey! What’s up?"])
|
| 10 |
+
elif "how are you" in message_lower:
|
| 11 |
+
response = random.choice(["I'm good! Thanks for asking.", "Doing great, how about you?", "All good here!"])
|
| 12 |
+
elif "your name" in message_lower:
|
| 13 |
+
response = "I'm your AI chatbot built with Gradio."
|
| 14 |
+
elif "bye" in message_lower:
|
| 15 |
+
response = "Goodbye! Have a great day!"
|
| 16 |
+
else:
|
| 17 |
+
response = "I'm not sure how to respond to that, but I'm learning!"
|
| 18 |
+
|
| 19 |
+
history.append((message, response))
|
| 20 |
+
return history, history
|
| 21 |
+
|
| 22 |
+
gr.ChatInterface(
|
| 23 |
+
fn=chat,
|
| 24 |
+
title="AI Chatbot",
|
| 25 |
+
description="A friendly chatbot built with Gradio",
|
| 26 |
+
theme="soft"
|
| 27 |
+
).launch()
|