Spaces:
Sleeping
Sleeping
| 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 | |
| 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 | |
| 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) | |