Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,28 @@
|
|
1 |
-
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
# Load the Hugging Face chatbot model (example: DialoGPT)
|
7 |
generator = pipeline("conversational", model="microsoft/DialoGPT-medium")
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
@app.route('/')
|
13 |
-
def index():
|
14 |
-
return "Food Customization Assistant is running"
|
15 |
-
|
16 |
-
@app.route('/chat', methods=['POST'])
|
17 |
-
def chat():
|
18 |
-
user_input = request.json.get('message')
|
19 |
-
if not user_input:
|
20 |
-
return jsonify({'error': 'No message provided'}), 400
|
21 |
-
|
22 |
-
# Generate a response using the Hugging Face model
|
23 |
response = generator(user_input)
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Initialize Hugging Face's DialoGPT model for conversational AI
|
|
|
|
|
5 |
generator = pipeline("conversational", model="microsoft/DialoGPT-medium")
|
6 |
|
7 |
+
# Function that interacts with the Hugging Face model
|
8 |
+
def chatbot_response(user_input):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
response = generator(user_input)
|
10 |
+
return response[0]['generated_text']
|
11 |
+
|
12 |
+
# Gradio interface setup
|
13 |
+
def create_gradio_interface():
|
14 |
+
# Create a Gradio interface with input and output components
|
15 |
+
interface = gr.Interface(
|
16 |
+
fn=chatbot_response,
|
17 |
+
inputs=gr.Textbox(label="Your Message", placeholder="Ask about food customization..."),
|
18 |
+
outputs=gr.Textbox(label="Bot Response"),
|
19 |
+
title="Food Customization Assistant",
|
20 |
+
description="Talk to the bot and customize your food preferences. Ask about recipes, categories, or ingredients.",
|
21 |
+
theme="compact" # You can customize the theme
|
22 |
+
)
|
23 |
+
|
24 |
+
return interface
|
25 |
+
|
26 |
+
if __name__ == "__main__":
|
27 |
+
interface = create_gradio_interface()
|
28 |
+
interface.launch()
|