Rammohan0504 commited on
Commit
8ce46dc
·
verified ·
1 Parent(s): bd7e8ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -39
app.py CHANGED
@@ -1,82 +1,86 @@
1
  import gradio as gr
2
 
3
  # Menu data with all details
4
- menu_data = {
5
- "ALL": [
6
- {"name": "Veg Burger", "category": "VEGAN",
7
- "image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
8
- "description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.",
9
- "price": "$8.99", "spice_level": "Medium", "portion_size": "Regular"},
10
- {"name": "Chicken Biryani", "category": "HALAL",
11
- "image": "https://upload.wikimedia.org/wikipedia/commons/7/79/Chicken_Biryani.jpg",
12
- "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
13
- "price": "$12.99", "spice_level": "High", "portion_size": "Large"},
14
- {"name": "Paneer Butter Masala", "category": "VEGAN",
15
- "image": "https://upload.wikimedia.org/wikipedia/commons/3/3d/Paneer_Butter_Masala.jpg",
16
- "description": "Paneer cooked in a rich and creamy tomato-based gravy.",
17
- "price": "$10.99", "spice_level": "Mild", "portion_size": "Medium"},
18
- {"name": "Beef Steak", "category": "HALAL",
19
- "image": "https://upload.wikimedia.org/wikipedia/commons/d/d5/Beef_Steak.jpg",
20
- "description": "Juicy beef steak served with mashed potatoes and grilled vegetables.",
21
- "price": "$14.99", "spice_level": "Medium", "portion_size": "Large"}
22
- ]
23
- }
24
 
25
  # Function to filter dishes based on category
26
  def filter_dishes(category):
27
- return [dish["name"] for dish in menu_data["ALL"] if category == "ALL" or dish["category"] == category]
28
 
29
- # Function to display details for a selected dish
30
  def get_dish_details(dish_name):
 
31
  fallback_image = "https://via.placeholder.com/300x200.png?text=No+Image+Available"
32
- for dish in menu_data["ALL"]:
 
 
 
33
  if dish["name"] == dish_name:
34
  return (
35
  dish.get("image", fallback_image),
36
- dish.get("description", "No description available."),
37
- dish.get("price", "N/A"),
38
- dish.get("spice_level", "N/A"),
39
- dish.get("portion_size", "N/A"),
40
  )
41
- return fallback_image, "Dish not found.", "N/A", "N/A", "N/A"
 
42
 
43
- # Main Gradio app
44
  with gr.Blocks() as demo:
45
  gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
46
 
47
- # Category Buttons
48
  gr.Markdown("### Select a Category")
49
  with gr.Row():
50
  btn_all = gr.Button("ALL")
51
  btn_vegan = gr.Button("VEGAN")
52
  btn_halal = gr.Button("HALAL")
53
 
54
- # Dish Selection (Radio Button)
55
  gr.Markdown("### Available Dishes")
56
  dish_radio = gr.Radio(choices=filter_dishes("ALL"), label="Select a Dish", interactive=True)
57
 
58
  # Dish Details
59
  gr.Markdown("### Dish Details")
60
- dish_image = gr.Image(label="Dish Image")
61
  dish_description = gr.Textbox(label="Description", interactive=False)
62
  dish_price = gr.Textbox(label="Price", interactive=False)
63
  dish_spice_level = gr.Textbox(label="Spice Level", interactive=False)
64
  dish_portion_size = gr.Textbox(label="Portion Size", interactive=False)
65
 
66
- # Event: Update dish list when a category button is clicked
67
  def update_dishes(category):
68
- return gr.update(choices=filter_dishes(category), value=None)
 
69
 
70
- btn_all.click(fn=lambda: update_dishes("ALL"), outputs=dish_radio)
71
- btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_radio)
72
- btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_radio)
73
 
74
- # Event: Show dish details when a dish is selected
75
  dish_radio.change(
76
  fn=get_dish_details,
77
  inputs=dish_radio,
78
  outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size]
79
  )
80
 
81
- # Launch the app
82
  demo.launch()
 
1
  import gradio as gr
2
 
3
  # Menu data with all 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
+ "price": "$8.99", "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
+ "price": "$12.99", "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
+ "price": "$10.99", "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
+ "price": "$14.99", "spice_level": "Medium", "portion_size": "Large"}
21
+ ]
 
 
22
 
23
  # Function to filter dishes based on category
24
  def filter_dishes(category):
25
+ return [dish["name"] for dish in menu_data if category == "ALL" or dish["category"] == category]
26
 
27
+ # Function to fetch details for a selected dish
28
  def get_dish_details(dish_name):
29
+ # Fallback values for missing or invalid data
30
  fallback_image = "https://via.placeholder.com/300x200.png?text=No+Image+Available"
31
+ fallback_text = "Information not available"
32
+
33
+ # Find the selected dish
34
+ for dish in menu_data:
35
  if dish["name"] == dish_name:
36
  return (
37
  dish.get("image", fallback_image),
38
+ dish.get("description", fallback_text),
39
+ dish.get("price", fallback_text),
40
+ dish.get("spice_level", fallback_text),
41
+ dish.get("portion_size", fallback_text),
42
  )
43
+ # If dish is not found, return fallbacks
44
+ return fallback_image, fallback_text, fallback_text, fallback_text, fallback_text
45
 
46
+ # Main Gradio App
47
  with gr.Blocks() as demo:
48
  gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
49
 
50
+ # Category Selection
51
  gr.Markdown("### Select a Category")
52
  with gr.Row():
53
  btn_all = gr.Button("ALL")
54
  btn_vegan = gr.Button("VEGAN")
55
  btn_halal = gr.Button("HALAL")
56
 
57
+ # Dish Selection Radio
58
  gr.Markdown("### Available Dishes")
59
  dish_radio = gr.Radio(choices=filter_dishes("ALL"), label="Select a Dish", interactive=True)
60
 
61
  # Dish Details
62
  gr.Markdown("### Dish Details")
63
+ dish_image = gr.Image(label="Dish Image", type="pil")
64
  dish_description = gr.Textbox(label="Description", interactive=False)
65
  dish_price = gr.Textbox(label="Price", interactive=False)
66
  dish_spice_level = gr.Textbox(label="Spice Level", interactive=False)
67
  dish_portion_size = gr.Textbox(label="Portion Size", interactive=False)
68
 
69
+ # Update the dish list when category buttons are clicked
70
  def update_dishes(category):
71
+ new_dishes = filter_dishes(category)
72
+ return gr.update(choices=new_dishes, value=None), "", "", "", "", ""
73
 
74
+ btn_all.click(fn=lambda: update_dishes("ALL"), outputs=[dish_radio, dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size])
75
+ btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=[dish_radio, dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size])
76
+ btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=[dish_radio, dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size])
77
 
78
+ # Update dish details when a dish is selected
79
  dish_radio.change(
80
  fn=get_dish_details,
81
  inputs=dish_radio,
82
  outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size]
83
  )
84
 
85
+ # Run the Gradio app
86
  demo.launch()