Spaces:
Running
Running
Upload 3 files
Browse files- README.md +50 -12
- app.py +64 -0
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -1,12 +1,50 @@
|
|
| 1 |
-
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: AI Chatbot
|
| 3 |
+
emoji: π€
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.0.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
short_description: A simple AI chatbot built with Gradio
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# AI Chatbot
|
| 15 |
+
|
| 16 |
+
A simple conversational AI chatbot built with Gradio. This chatbot can respond to basic greetings and engage in simple conversations.
|
| 17 |
+
|
| 18 |
+
## Features
|
| 19 |
+
|
| 20 |
+
- Interactive chat interface
|
| 21 |
+
- Simple pattern-based responses
|
| 22 |
+
- Clean and modern UI
|
| 23 |
+
- Easy to use and deploy
|
| 24 |
+
|
| 25 |
+
## How to Use
|
| 26 |
+
|
| 27 |
+
1. Type your message in the text box
|
| 28 |
+
2. Click "Send" or press Enter
|
| 29 |
+
3. The chatbot will respond based on your input
|
| 30 |
+
4. Try saying "hello" or "bye" to see the chatbot in action!
|
| 31 |
+
|
| 32 |
+
## Local Development
|
| 33 |
+
|
| 34 |
+
To run this chatbot locally:
|
| 35 |
+
|
| 36 |
+
1. Install the requirements:
|
| 37 |
+
```bash
|
| 38 |
+
pip install -r requirements.txt
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
2. Run the application:
|
| 42 |
+
```bash
|
| 43 |
+
python app.py
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
3. Open your browser and go to `http://localhost:7860`
|
| 47 |
+
|
| 48 |
+
## Deployment
|
| 49 |
+
|
| 50 |
+
This app is designed to be deployed on Hugging Face Spaces. Simply push this repository to a Hugging Face Space and it will automatically deploy with Gradio.
|
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
def chatbot_response(message, history):
|
| 5 |
+
"""Process user input and return chatbot response"""
|
| 6 |
+
user_input = message.lower()
|
| 7 |
+
|
| 8 |
+
if "hello" in user_input:
|
| 9 |
+
return "Hello there! How can I help you today?"
|
| 10 |
+
elif "bye" in user_input:
|
| 11 |
+
return "Goodbye! π"
|
| 12 |
+
else:
|
| 13 |
+
return f"You said: {message}. I'm still learning!"
|
| 14 |
+
|
| 15 |
+
# Create Gradio interface
|
| 16 |
+
with gr.Blocks(title="AI Chatbot", theme=gr.themes.Soft()) as demo:
|
| 17 |
+
gr.Markdown("# π€ AI Chatbot")
|
| 18 |
+
gr.Markdown("Welcome to my simple AI chatbot! Try saying 'hello' or 'bye'.")
|
| 19 |
+
|
| 20 |
+
# Chat interface
|
| 21 |
+
chatbot = gr.Chatbot(
|
| 22 |
+
label="Chat",
|
| 23 |
+
height=400,
|
| 24 |
+
show_label=True,
|
| 25 |
+
container=True,
|
| 26 |
+
bubble_full_width=False
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Text input
|
| 30 |
+
msg = gr.Textbox(
|
| 31 |
+
label="Your message",
|
| 32 |
+
placeholder="Type your message here...",
|
| 33 |
+
lines=1,
|
| 34 |
+
max_lines=3,
|
| 35 |
+
show_label=True
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Submit button
|
| 39 |
+
submit_btn = gr.Button("Send", variant="primary")
|
| 40 |
+
|
| 41 |
+
# Clear button
|
| 42 |
+
clear_btn = gr.Button("Clear", variant="secondary")
|
| 43 |
+
|
| 44 |
+
# Event handlers
|
| 45 |
+
def user(user_message, history):
|
| 46 |
+
return "", history + [[user_message, None]]
|
| 47 |
+
|
| 48 |
+
def bot(history):
|
| 49 |
+
user_message = history[-1][0]
|
| 50 |
+
bot_message = chatbot_response(user_message, history)
|
| 51 |
+
history[-1][1] = bot_message
|
| 52 |
+
return history
|
| 53 |
+
|
| 54 |
+
# Connect the interface
|
| 55 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 56 |
+
bot, chatbot, chatbot
|
| 57 |
+
)
|
| 58 |
+
submit_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 59 |
+
bot, chatbot, chatbot
|
| 60 |
+
)
|
| 61 |
+
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|