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