Rammohan0504 commited on
Commit
3f35adb
ยท
verified ยท
1 Parent(s): 8c97028

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -111
app.py CHANGED
@@ -1,92 +1,17 @@
1
- import gradio as gr
2
-
3
- # Extended menu data with dish details
4
- menu_data = [
5
- {"name": "Veg Burger", "category": "VEGAN",
6
- "image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
7
- "description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.",
8
- "spice_level": "Medium", "portion_size": "Regular"},
9
- {"name": "Chicken Biryani", "category": "HALAL",
10
- "image": "https://upload.wikimedia.org/wikipedia/commons/7/79/Chicken_Biryani.jpg",
11
- "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
12
- "spice_level": "High", "portion_size": "Large"},
13
- {"name": "Paneer Butter Masala", "category": "VEGAN",
14
- "image": "https://upload.wikimedia.org/wikipedia/commons/3/3d/Paneer_Butter_Masala.jpg",
15
- "description": "Paneer cooked in a rich and creamy tomato-based gravy.",
16
- "spice_level": "Mild", "portion_size": "Medium"},
17
- {"name": "Beef Steak", "category": "HALAL",
18
- "image": "https://upload.wikimedia.org/wikipedia/commons/d/d5/Beef_Steak.jpg",
19
- "description": "Juicy beef steak served with mashed potatoes and grilled vegetables.",
20
- "spice_level": "Medium", "portion_size": "Large"},
21
- {"name": "Mushroom Soup", "category": "VEGAN",
22
- "image": "https://upload.wikimedia.org/wikipedia/commons/3/3c/Mushroom_Soup.jpg",
23
- "description": "Creamy mushroom soup with fresh herbs.",
24
- "spice_level": "Mild", "portion_size": "Small"},
25
- {"name": "Pasta Alfredo", "category": "VEGAN",
26
- "image": "https://upload.wikimedia.org/wikipedia/commons/4/44/Fettuccine_Alfredo.jpg",
27
- "description": "Rich and creamy Alfredo pasta topped with fresh parsley.",
28
- "spice_level": "Mild", "portion_size": "Medium"},
29
- {"name": "Grilled Chicken", "category": "HALAL",
30
- "image": "https://upload.wikimedia.org/wikipedia/commons/6/65/Grilled_Chicken.jpg",
31
- "description": "Succulent grilled chicken served with a side of vegetables.",
32
- "spice_level": "Medium", "portion_size": "Large"},
33
- {"name": "Caesar Salad", "category": "VEGAN",
34
- "image": "https://upload.wikimedia.org/wikipedia/commons/4/4d/Caesar_Salad.jpg",
35
- "description": "Fresh Caesar salad with crispy croutons and creamy dressing.",
36
- "spice_level": "Mild", "portion_size": "Small"}
37
- ]
38
-
39
- spice_options = ["๐ŸŒถ Mild", "๐ŸŒถ๐ŸŒถ Medium", "๐ŸŒถ๐ŸŒถ๐ŸŒถ High"]
40
- portion_options = ["๐Ÿง† Small", "๐Ÿฝ Medium", "๐Ÿ› Large"]
41
-
42
- def filter_dishes(category):
43
- if category == "ALL":
44
- return menu_data
45
- return [dish for dish in menu_data if dish["category"] == category]
46
-
47
- def display_dishes(category):
48
- filtered_dishes = filter_dishes(category)
49
- html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
50
- for dish in filtered_dishes:
51
- html_content += f"""
52
- <div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
53
- padding: 10px; border-radius: 10px; width: 200px; background-color: #f9f9f9;'
54
- onclick='selectDish("{dish['name']}")'>
55
- <img src='{dish['image']}' alt='{dish['name']}'
56
- style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
57
- <h4 style='margin-top: 10px; font-size: 16px; color: #444;'>{dish['name']}</h4>
58
- </div>
59
- """
60
- html_content += "</div>"
61
- return html_content
62
-
63
- def get_dish_details(dish_name):
64
- for dish in menu_data:
65
- if dish["name"] == dish_name:
66
- # JavaScript to simulate a click event
67
- return (
68
- dish["image"],
69
- dish["name"],
70
- dish["description"],
71
- f"<script>selectDish('{dish_name}');</script>",
72
- "๐ŸŒถ Medium",
73
- "๐Ÿฝ Medium",
74
- )
75
- # Return placeholder if no match
76
- return (
77
- "https://via.placeholder.com/300x200",
78
- "Unknown Dish",
79
- "No description available.",
80
- f"<script>alert('Dish not found!');</script>",
81
- "N/A",
82
- "N/A",
83
- )
84
-
85
- def place_order(dish_name, spice_level, portion_size):
86
- return f"โœ… Order Confirmed: '{dish_name}' with {spice_level} spice level and {portion_size} portion size."
87
-
88
  with gr.Blocks() as demo:
89
- gr.HTML("<h1 style='text-align: center; color: #333;'>๐Ÿ› Biryani Hub Menu ๐Ÿ›</h1>")
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
  gr.Markdown("### Select a Category")
92
  with gr.Row():
@@ -97,7 +22,6 @@ with gr.Blocks() as demo:
97
  gr.Markdown("### Available Dishes")
98
  dish_display = gr.HTML(value=display_dishes("ALL"))
99
 
100
- # Dish Details Pop-up
101
  popup = gr.Group(visible=False)
102
  with popup:
103
  with gr.Row():
@@ -119,31 +43,15 @@ with gr.Blocks() as demo:
119
  btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
120
  btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
121
 
122
- def show_dish_details(dish_name):
123
- image, name, description, spice, portion = get_dish_details(dish_name)
124
- return gr.update(visible=True), image, name, description, spice, portion
125
-
126
- def close_dish_popup():
127
- return gr.update(visible=False)
128
-
129
  selected_dish_name = gr.Textbox(visible=False)
130
- selected_dish_name.change(fn=show_dish_details, inputs=selected_dish_name,
131
- outputs=[popup, dish_image, dish_name, dish_description, spice_dropdown, portion_dropdown])
 
 
 
132
 
133
  close_popup.click(fn=close_dish_popup, outputs=popup)
134
 
135
- place_order_btn.click(fn=place_order,
136
- inputs=[dish_name, spice_dropdown, portion_dropdown],
137
- outputs=order_status)
138
-
139
- gr.HTML("""
140
- <script>
141
- function selectDish(dishName) {
142
- let input = document.querySelector('input[aria-label="selected_dish_name"]');
143
- input.value = dishName;
144
- input.dispatchEvent(new Event('input', { bubbles: true }));
145
- }
146
- </script>
147
- """)
148
 
149
  demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  with gr.Blocks() as demo:
2
+ gr.HTML("<h1 style='text-align: center;'>๐Ÿ› Biryani Hub Menu ๐Ÿ›</h1>")
3
+
4
+ gr.HTML("""
5
+ <script>
6
+ function selectDish(dishName) {
7
+ let input = document.querySelector('input[aria-label="selected_dish_name"]');
8
+ if (input) {
9
+ input.value = dishName;
10
+ input.dispatchEvent(new Event('input', { bubbles: true }));
11
+ }
12
+ }
13
+ </script>
14
+ """)
15
 
16
  gr.Markdown("### Select a Category")
17
  with gr.Row():
 
22
  gr.Markdown("### Available Dishes")
23
  dish_display = gr.HTML(value=display_dishes("ALL"))
24
 
 
25
  popup = gr.Group(visible=False)
26
  with popup:
27
  with gr.Row():
 
43
  btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
44
  btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
45
 
 
 
 
 
 
 
 
46
  selected_dish_name = gr.Textbox(visible=False)
47
+ selected_dish_name.change(
48
+ fn=show_dish_details,
49
+ inputs=selected_dish_name,
50
+ outputs=[popup, dish_image, dish_name, dish_description, spice_dropdown, portion_dropdown],
51
+ )
52
 
53
  close_popup.click(fn=close_dish_popup, outputs=popup)
54
 
55
+ place_order_btn.click(fn=place_order, inputs=[dish_name, spice_dropdown, portion_dropdown], outputs=order_status)
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  demo.launch()