Yaswanth56 commited on
Commit
4ebc5ed
·
verified ·
1 Parent(s): 4b49726

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ import json
3
+
4
+ app = Flask(__name__)
5
+
6
+ # Expanded recipe database with categories
7
+ recipes = [
8
+ {
9
+ "name": "Classic Frappuccino",
10
+ "description": "A refreshing blended coffee drink topped with whipped cream",
11
+ "ingredients": ["coffee", "milk", "ice cream", "sugar", "whipped cream"],
12
+ "image": "https://images.unsplash.com/photo-1461023058943-07fcbe16d735?auto=format&fit=crop&q=80&w=1000",
13
+ "category": "beverages"
14
+ },
15
+ {
16
+ "name": "Mocha Frappe",
17
+ "description": "Rich chocolate and coffee blend topped with chocolate drizzle",
18
+ "ingredients": ["coffee", "chocolate", "milk", "ice cream", "whipped cream"],
19
+ "image": "https://images.unsplash.com/photo-1572490122747-3968b75cc699?auto=format&fit=crop&q=80&w=1000",
20
+ "category": "beverages"
21
+ },
22
+ {
23
+ "name": "Cold Brew Coffee",
24
+ "description": "Smooth, less acidic cold coffee perfect for hot days",
25
+ "ingredients": ["coffee", "water", "ice"],
26
+ "image": "https://images.unsplash.com/photo-1461023058943-07fcbe16d735?auto=format&fit=crop&q=80&w=1000",
27
+ "category": "beverages"
28
+ },
29
+ {
30
+ "name": "Bellam Paysam",
31
+ "description": "A traditional sweet rice pudding made with jaggery",
32
+ "ingredients": ["rice", "milk", "jaggery", "cardamom", "cashews"],
33
+ "image": "https://images.unsplash.com/photo-1633383718081-22ac93e3db65?auto=format&fit=crop&q=80&w=1000",
34
+ "category": "desserts"
35
+ },
36
+ {
37
+ "name": "Rice Kheer",
38
+ "description": "Creamy rice pudding with cardamom and nuts",
39
+ "ingredients": ["rice", "milk", "sugar", "cardamom", "almonds", "raisins"],
40
+ "image": "https://images.unsplash.com/photo-1639461161574-c11f0d2cca49?auto=format&fit=crop&q=80&w=1000",
41
+ "category": "desserts"
42
+ },
43
+ {
44
+ "name": "Masala Dosa",
45
+ "description": "Crispy fermented crepe filled with spiced potatoes",
46
+ "ingredients": ["rice", "urad dal", "potatoes", "onions", "mustard seeds", "turmeric"],
47
+ "image": "https://images.unsplash.com/photo-1589301760014-d929f3979dbc?auto=format&fit=crop&q=80&w=1000",
48
+ "category": "main course"
49
+ },
50
+ {
51
+ "name": "Vegetable Biryani",
52
+ "description": "Aromatic rice dish with mixed vegetables and spices",
53
+ "ingredients": ["basmati rice", "mixed vegetables", "onions", "yogurt", "biryani masala", "saffron"],
54
+ "image": "https://images.unsplash.com/photo-1563379091339-03b21ab4a4f8?auto=format&fit=crop&q=80&w=1000",
55
+ "category": "main course"
56
+ }
57
+ ]
58
+
59
+ # Helper function to find similar recipes
60
+ def find_similar_recipes(ingredients):
61
+ scored_recipes = []
62
+ for recipe in recipes:
63
+ matching_ingredients = [ri for ri in recipe['ingredients'] if any(i in ri.lower() for i in ingredients)]
64
+ score = len(matching_ingredients) / len(ingredients)
65
+ if score >= 0.3:
66
+ scored_recipes.append({**recipe, "matchScore": round(score * 100)})
67
+ scored_recipes.sort(key=lambda x: x["matchScore"], reverse=True)
68
+ return scored_recipes
69
+
70
+ @app.route('/')
71
+ def index():
72
+ return render_template('index.html')
73
+
74
+ @app.route('/get_recipes', methods=['POST'])
75
+ def get_recipes():
76
+ user_input = request.json['input']
77
+ ingredients = [i.strip().lower() for i in user_input.split('+')]
78
+ similar_recipes = find_similar_recipes(ingredients)
79
+ return jsonify(similar_recipes)
80
+
81
+ if __name__ == '__main__':
82
+ app.run(debug=True)