Rammohan0504 commited on
Commit
bd7e8ba
·
verified ·
1 Parent(s): 4a0f1fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -22,57 +22,61 @@ menu_data = {
22
  ]
23
  }
24
 
25
- # 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
- # Get dish details
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", "Description not 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
- category_buttons = gr.Button(["ALL", "VEGAN", "HALAL"])
 
 
51
 
52
- # Dish Selection Radio
53
- gr.Markdown("### Select a Dish")
54
- dish_radio = gr.Radio(choices=[], label="Available Dishes", interactive=True)
55
 
56
  # Dish Details
57
  gr.Markdown("### Dish Details")
58
- dish_image = gr.Image(label="Dish Image", type="pil")
59
  dish_description = gr.Textbox(label="Description", interactive=False)
60
  dish_price = gr.Textbox(label="Price", interactive=False)
61
  dish_spice_level = gr.Textbox(label="Spice Level", interactive=False)
62
  dish_portion_size = gr.Textbox(label="Portion Size", interactive=False)
63
 
64
- # Update the dish list when category buttons are clicked
65
  def update_dishes(category):
66
  return gr.update(choices=filter_dishes(category), value=None)
67
 
68
- category_buttons.select(fn=update_dishes, inputs=category_buttons, outputs=dish_radio)
 
 
69
 
70
- # Update dish details dynamically
71
  dish_radio.change(
72
  fn=get_dish_details,
73
  inputs=dish_radio,
74
  outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size]
75
  )
76
 
77
- # Run the Gradio app
78
  demo.launch()
 
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()