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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -47
app.py CHANGED
@@ -1,6 +1,6 @@
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",
@@ -24,63 +24,61 @@ menu_data = [
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()
 
 
 
 
1
  import gradio as gr
2
 
3
+ # Menu data
4
  menu_data = [
5
  {"name": "Veg Burger", "category": "VEGAN",
6
  "image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
 
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 get dish details
28
  def get_dish_details(dish_name):
29
+ fallback_image = "https://via.placeholder.com/300x200.png?text=No+Image"
 
 
 
 
30
  for dish in menu_data:
31
  if dish["name"] == dish_name:
32
  return (
33
  dish.get("image", fallback_image),
34
+ dish.get("description", "Description not available"),
35
+ dish.get("price", "N/A"),
36
+ dish.get("spice_level", "N/A"),
37
+ dish.get("portion_size", "N/A")
38
  )
39
+ return fallback_image, "Dish not found", "N/A", "N/A", "N/A"
 
40
 
41
+ # Gradio app
42
+ def create_ui():
43
+ with gr.Blocks() as demo:
44
+ gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
45
 
46
+ # Category Buttons
47
+ gr.Markdown("### Select a Category")
48
+ with gr.Row():
49
+ btn_all = gr.Button("ALL")
50
+ btn_vegan = gr.Button("VEGAN")
51
+ btn_halal = gr.Button("HALAL")
52
 
53
+ # Dropdown for Dish Selection
54
+ gr.Markdown("### Available Dishes")
55
+ dish_dropdown = gr.Dropdown(choices=filter_dishes("ALL"), label="Select a Dish", interactive=True)
56
 
57
+ # Dish Details
58
+ gr.Markdown("### Dish Details")
59
+ dish_image = gr.Image(label="Dish Image")
60
+ dish_description = gr.Textbox(label="Description", interactive=False)
61
+ dish_price = gr.Textbox(label="Price", interactive=False)
62
+ dish_spice_level = gr.Textbox(label="Spice Level", interactive=False)
63
+ dish_portion_size = gr.Textbox(label="Portion Size", interactive=False)
64
 
65
+ # Event: Update dish list when a category button is clicked
66
+ def update_dish_list(category):
67
+ return gr.update(choices=filter_dishes(category), value=None)
 
68
 
69
+ btn_all.click(fn=lambda: update_dish_list("ALL"), outputs=dish_dropdown)
70
+ btn_vegan.click(fn=lambda: update_dish_list("VEGAN"), outputs=dish_dropdown)
71
+ btn_halal.click(fn=lambda: update_dish_list("HALAL"), outputs=dish_dropdown)
72
 
73
+ # Event: Display dish details when a dish is selected
74
+ dish_dropdown.change(
75
+ fn=get_dish_details,
76
+ inputs=dish_dropdown,
77
+ outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size]
78
+ )
79
 
80
+ return demo
81
+
82
+ # Run the app
83
+ if __name__ == "__main__":
84
+ create_ui().launch()