Subbu1304 commited on
Commit
34e2abf
·
verified ·
1 Parent(s): ab09773

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)