Rammohan0504 commited on
Commit
4558d64
Β·
verified Β·
1 Parent(s): c1181f6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -0
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ]
26
+
27
+ spice_options = ["🌢 Mild", "🌢🌢 Medium", "🌢🌢🌢 High"]
28
+ portion_options = ["πŸ§† Small", "🍽 Medium", "πŸ› Large"]
29
+
30
+ # Function to display dishes dynamically
31
+ def display_dishes():
32
+ html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
33
+ for dish in menu_data:
34
+ html_content += f"""
35
+ <div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
36
+ padding: 10px; border-radius: 10px; width: 200px; background-color: #f9f9f9;'
37
+ onclick='selectDish("{dish['name']}")'>
38
+ <img src='{dish['image']}' alt='{dish['name']}'
39
+ style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
40
+ <h4 style='margin-top: 10px; font-size: 16px; color: #444;'>{dish['name']}</h4>
41
+ </div>
42
+ """
43
+ html_content += "</div>"
44
+ return html_content
45
+
46
+ # Function to get dish details
47
+ def get_dish_details(dish_name):
48
+ for dish in menu_data:
49
+ if dish["name"] == dish_name:
50
+ return dish["image"], dish["name"], dish["description"], spice_options[1], portion_options[1]
51
+ return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available.", "🌢 Medium", "🍽 Medium"
52
+
53
+ # Function to simulate placing an order
54
+ def place_order(dish_name, spice_level, portion_size):
55
+ return f"βœ… Order Confirmed: '{dish_name}' with {spice_level} spice level and {portion_size} portion size."
56
+
57
+ # Gradio App
58
+ with gr.Blocks() as demo:
59
+ gr.HTML("<h1 style='text-align: center;'>πŸ› Biryani Hub Menu πŸ›</h1>")
60
+
61
+ # Display available dishes
62
+ dish_display = gr.HTML(value=display_dishes())
63
+
64
+ # Dish Details Section
65
+ gr.Markdown("### Dish Details")
66
+ with gr.Row():
67
+ dish_image = gr.Image(label="Dish Image", height=200, width=200)
68
+ with gr.Column():
69
+ dish_name = gr.Textbox(label="Dish Name", interactive=False)
70
+ dish_description = gr.Textbox(label="Description", interactive=False)
71
+ spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="🌢 Medium")
72
+ portion_dropdown = gr.Radio(label="Select Portion Size", choices=portion_options, value="🍽 Medium")
73
+ place_order_btn = gr.Button("Place Order")
74
+ order_status = gr.Textbox(label="Order Status", interactive=False)
75
+
76
+ # Event to show dish details
77
+ def update_dish_details(dish_name):
78
+ return get_dish_details(dish_name)
79
+
80
+ # Hidden textbox to capture JavaScript input
81
+ selected_dish_name = gr.Textbox(visible=False)
82
+ selected_dish_name.change(
83
+ fn=update_dish_details,
84
+ inputs=selected_dish_name,
85
+ outputs=[dish_image, dish_name, dish_description, spice_dropdown, portion_dropdown]
86
+ )
87
+
88
+ # Place Order Event
89
+ place_order_btn.click(fn=place_order, inputs=[dish_name, spice_dropdown, portion_dropdown], outputs=order_status)
90
+
91
+ # JavaScript to select dish and trigger event
92
+ gr.HTML("""
93
+ <script>
94
+ function selectDish(dishName) {
95
+ const input = document.querySelector('input[aria-label="selected_dish_name"]');
96
+ input.value = dishName;
97
+ input.dispatchEvent(new Event('input', { bubbles: true }));
98
+ }
99
+ </script>
100
+ """)
101
+
102
+ demo.launch()