DSatishchandra commited on
Commit
e8b45b6
·
verified ·
1 Parent(s): 2f9fd86

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from transformers import pipeline
3
+
4
+ app = Flask(__name__)
5
+
6
+ # Load Hugging Face model for conversation
7
+ chatbot = pipeline("conversational", model="facebook/blenderbot-400M-distill")
8
+
9
+ # Endpoint for chat with the chatbot
10
+ @app.route('/chat', methods=['POST'])
11
+ def chat():
12
+ user_message = request.json.get('message')
13
+
14
+ if user_message.lower() == 'hi':
15
+ # Send a greeting message when the user says "hi"
16
+ return jsonify({"response": "Hello! Welcome to the Indian Recipe Bot. What ingredients do you have today?"})
17
+
18
+ # Get response from the chatbot model
19
+ chatbot_response = chatbot(user_message)
20
+ return jsonify({"response": chatbot_response[0]['generated_text']})
21
+
22
+
23
+ @app.route('/ingredients', methods=['POST'])
24
+ def ingredients():
25
+ user_ingredients = request.json.get('ingredients')
26
+
27
+ # Example logic to suggest Indian recipes based on ingredients
28
+ recipes = {
29
+ 'rice': ['Biryani', 'Pulao'],
30
+ 'potato': ['Aloo Gobi', 'Aloo Paratha'],
31
+ 'spinach': ['Palak Paneer', 'Saag Aloo'],
32
+ 'chicken': ['Butter Chicken', 'Chicken Curry'],
33
+ 'paneer': ['Paneer Butter Masala', 'Shahi Paneer'],
34
+ }
35
+
36
+ suggested_recipes = []
37
+ for ingredient in user_ingredients:
38
+ if ingredient in recipes:
39
+ suggested_recipes.extend(recipes[ingredient])
40
+
41
+ if not suggested_recipes:
42
+ suggested_recipes.append('Sorry, no recipes found for the ingredients you provided.')
43
+
44
+ return jsonify({"suggested_recipes": suggested_recipes})
45
+
46
+
47
+ if __name__ == '__main__':
48
+ app.run(debug=True)