DSatishchandra commited on
Commit
7980609
·
verified ·
1 Parent(s): 7395228

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ import pandas as pd
3
+
4
+ app = Flask(__name__)
5
+
6
+ # Load the menu data
7
+ def load_menu(file_path="menu.xlsx"):
8
+ menu_data = pd.read_excel(file_path)
9
+ grouped_menu = menu_data.groupby("Category")
10
+ return grouped_menu
11
+
12
+ # Route to serve the menu
13
+ @app.route("/")
14
+ def index():
15
+ grouped_menu = load_menu()
16
+ menu = {category: items.to_dict(orient="records") for category, items in grouped_menu}
17
+ return render_template("index.html", menu=menu)
18
+
19
+ # API route to get menu item details
20
+ @app.route("/menu_item", methods=["POST"])
21
+ def menu_item():
22
+ data = request.json
23
+ item_name = data.get("dish_name")
24
+
25
+ # Load the menu and find the item
26
+ menu_data = pd.read_excel("menu.xlsx")
27
+ item = menu_data[menu_data["Dish Name"] == item_name].to_dict(orient="records")
28
+
29
+ if item:
30
+ return jsonify(item[0]) # Return the first matching item as JSON
31
+ else:
32
+ return jsonify({"error": "Dish not found"}), 404
33
+
34
+ if __name__ == "__main__":
35
+ app.run(debug=True)