Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import json
|
3 |
+
|
4 |
+
|
5 |
+
# Load menu data
|
6 |
+
def load_menu_data():
|
7 |
+
with open("data/menu.json", "r") as file:
|
8 |
+
return json.load(file)
|
9 |
+
|
10 |
+
|
11 |
+
# Function to render the popup card
|
12 |
+
def render_popup(item):
|
13 |
+
return f"""
|
14 |
+
<div class='popup'>
|
15 |
+
<div class='popup-header'>
|
16 |
+
<h2>{item['name']}</h2>
|
17 |
+
<button class='close-btn' onclick="closePopup()">×</button>
|
18 |
+
</div>
|
19 |
+
<img src='{item['image']}' alt='{item['name']}' class='popup-image'>
|
20 |
+
<p>{item['description']}</p>
|
21 |
+
<div class='nutrition-info'>
|
22 |
+
<p><strong>Nutrition:</strong> {item['nutrition']}</p>
|
23 |
+
</div>
|
24 |
+
<button class='add-btn'>Add to Order (${item['price']})</button>
|
25 |
+
</div>
|
26 |
+
"""
|
27 |
+
|
28 |
+
|
29 |
+
# Gradio UI
|
30 |
+
def menu_ui():
|
31 |
+
menu_data = load_menu_data()
|
32 |
+
|
33 |
+
with gr.Blocks(css="assets/style.css") as app:
|
34 |
+
gr.Markdown("<h1>Dynamic Menu with Preferences</h1>")
|
35 |
+
|
36 |
+
# Preferences Section
|
37 |
+
with gr.Row():
|
38 |
+
gr.Radio(["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"], label="Choose a Preference", value="All")
|
39 |
+
|
40 |
+
# Menu Items
|
41 |
+
menu_items = gr.Markdown()
|
42 |
+
|
43 |
+
for item in menu_data:
|
44 |
+
with gr.Row():
|
45 |
+
with gr.Column(scale=3):
|
46 |
+
gr.Markdown(f"**{item['name']}** \n${item['price']} \n{item['description']}")
|
47 |
+
with gr.Column(scale=1):
|
48 |
+
gr.Image(item['image'], elem_id="food-image")
|
49 |
+
gr.Button("Add").click(lambda x=item: render_popup(x), outputs=menu_items)
|
50 |
+
|
51 |
+
# Popup card
|
52 |
+
menu_items.render()
|
53 |
+
|
54 |
+
return app
|
55 |
+
|
56 |
+
|
57 |
+
# Run the app
|
58 |
+
if __name__ == "__main__":
|
59 |
+
menu_ui().launch()
|