Subbu1304 commited on
Commit
d922512
·
verified ·
1 Parent(s): 2650543

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -27
app.py CHANGED
@@ -1,32 +1,28 @@
1
- from flask import Flask, jsonify, request
2
  from transformers import pipeline
3
 
4
- app = Flask(__name__)
5
-
6
- # Load the Hugging Face chatbot model (example: DialoGPT)
7
  generator = pipeline("conversational", model="microsoft/DialoGPT-medium")
8
 
9
- # Initialize the chatbot with a starting message
10
- initial_message = "Hi! Would you like to customize food?"
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
- bot_reply = response[0]['generated_text']
25
-
26
- return jsonify({
27
- 'user_message': user_input,
28
- 'bot_message': bot_reply
29
- })
30
-
31
- if __name__ == '__main__':
32
- app.run(debug=True)
 
 
 
 
 
 
 
 
 
 
 
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()