Rammohan0504 commited on
Commit
e12727a
·
verified ·
1 Parent(s): c32da80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -39
app.py CHANGED
@@ -1,74 +1,112 @@
1
  import gradio as gr
2
 
3
- # Define available dishes and their portion sizes with image paths
4
  dish_data = {
5
  "Pizza": {
6
- "main": "pizza_main.jpg",
7
- "small": "pizza_small.jpg",
8
- "medium": "pizza_medium.jpg",
9
- "large": "pizza_large.jpg",
 
10
  },
11
- "Burger": {
12
- "main": "images/burger_main.jpg",
13
- "small": "images/burger_small.jpg",
14
- "medium": "images/burger_medium.jpg",
15
- "large": "images/burger_large.jpg",
 
16
  },
17
- "Pasta": {
18
- "main": "images/pasta_main.jpg",
19
- "small": "images/pasta_small.jpg",
20
- "medium": "images/pasta_medium.jpg",
21
- "large": "images/pasta_large.jpg",
 
 
 
 
 
 
 
 
22
  },
23
  }
24
 
25
- # Function to handle displaying the main dish image and enabling portion buttons
 
 
26
  def display_dish(dish):
27
  if dish not in dish_data:
28
- return None, dish, gr.update(visible=False)
29
  main_image = dish_data[dish]["main"]
30
- return main_image, dish, gr.update(visible=True)
31
 
32
- # Function to handle displaying the portion size image
33
  def display_portion(dish, portion):
34
  if dish not in dish_data:
35
  return None
36
  portion_image = dish_data[dish].get(portion, None)
37
  return portion_image
38
 
 
 
 
39
  # Define the Gradio interface
40
  with gr.Blocks() as demo:
41
  gr.Markdown("# Food Ordering System")
42
 
43
- # Section to display dishes as clickable buttons
44
- with gr.Row():
45
- selected_dish = gr.State() # Store the selected dish
46
- main_image = gr.Image(label="Dish Image")
47
- dish_name_display = gr.Text(label="Dish Name")
48
- portion_row = gr.Row(visible=False) # Portion size buttons section
49
- portion_image = gr.Image(label="Portion Size Image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- dish_buttons = []
52
- for dish, data in dish_data.items():
53
- dish_buttons.append(gr.Button(value=dish, elem_id=f"button_{dish}"))
 
 
 
 
54
 
55
- # Section to display portion size buttons
56
  with portion_row:
57
  portion_buttons = []
58
  for portion in ["small", "medium", "large"]:
59
  portion_buttons.append(gr.Button(value=portion.capitalize()))
60
 
 
 
 
 
 
 
61
  # Link dish buttons to display the selected dish
62
- for button, dish in zip(dish_buttons, dish_data.keys()):
63
- button.click(
64
- fn=display_dish,
65
- inputs=[gr.Textbox(value=dish, visible=False)],
66
- outputs=[main_image, dish_name_display, portion_row],
67
- )
68
  button.click(
69
- fn=lambda x: x,
70
- inputs=[gr.Textbox(value=dish, visible=False)],
71
- outputs=selected_dish,
72
  )
73
 
74
  # Link portion buttons to display the portion image
@@ -79,5 +117,13 @@ with gr.Blocks() as demo:
79
  outputs=portion_image,
80
  )
81
 
 
 
 
 
 
 
 
 
82
  # Launch the Gradio app
83
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ # Define available dishes and their portion sizes with image paths and categories
4
  dish_data = {
5
  "Pizza": {
6
+ "main": "images/pizza_main.jpg",
7
+ "small": "images/pizza_small.jpg",
8
+ "medium": "images/pizza_medium.jpg",
9
+ "large": "images/pizza_large.jpg",
10
+ "category": "All",
11
  },
12
+ "Vegan Salad": {
13
+ "main": "images/vegan_salad_main.jpg",
14
+ "small": "images/vegan_salad_small.jpg",
15
+ "medium": "images/vegan_salad_medium.jpg",
16
+ "large": "images/vegan_salad_large.jpg",
17
+ "category": "Vegan",
18
  },
19
+ "Halal Chicken": {
20
+ "main": "images/halal_chicken_main.jpg",
21
+ "small": "images/halal_chicken_small.jpg",
22
+ "medium": "images/halal_chicken_medium.jpg",
23
+ "large": "images/halal_chicken_large.jpg",
24
+ "category": "Halal",
25
+ },
26
+ "Allergenic Soup": {
27
+ "main": "images/allergenic_soup_main.jpg",
28
+ "small": "images/allergenic_soup_small.jpg",
29
+ "medium": "images/allergenic_soup_medium.jpg",
30
+ "large": "images/allergenic_soup_large.jpg",
31
+ "category": "Allergenic",
32
  },
33
  }
34
 
35
+ def filter_dishes(category):
36
+ return {dish: data for dish, data in dish_data.items() if category == "All" or data["category"] == category}
37
+
38
  def display_dish(dish):
39
  if dish not in dish_data:
40
+ return None, dish, gr.update(visible=False), gr.update(visible=False)
41
  main_image = dish_data[dish]["main"]
42
+ return main_image, dish, gr.update(visible=True), gr.update(visible=True)
43
 
 
44
  def display_portion(dish, portion):
45
  if dish not in dish_data:
46
  return None
47
  portion_image = dish_data[dish].get(portion, None)
48
  return portion_image
49
 
50
+ def spice_level_selection(spice_level):
51
+ return f"Selected spice level: {spice_level}"
52
+
53
  # Define the Gradio interface
54
  with gr.Blocks() as demo:
55
  gr.Markdown("# Food Ordering System")
56
 
57
+ # Category selection
58
+ category_dropdown = gr.Dropdown(
59
+ choices=["All", "Vegan", "Halal", "Allergenic"],
60
+ value="All",
61
+ label="Select Category"
62
+ )
63
+
64
+ # Dynamic dish buttons
65
+ dish_buttons = gr.Row()
66
+
67
+ def update_dish_buttons(category):
68
+ filtered_dishes = filter_dishes(category)
69
+ buttons = []
70
+ for dish, data in filtered_dishes.items():
71
+ buttons.append(gr.Button(value=dish))
72
+ return buttons
73
+
74
+ category_dropdown.change(
75
+ fn=update_dish_buttons,
76
+ inputs=category_dropdown,
77
+ outputs=dish_buttons
78
+ )
79
 
80
+ # Section to display the main image of the selected dish
81
+ selected_dish = gr.State() # Store the selected dish
82
+ main_image = gr.Image(label="Dish Image")
83
+ dish_name_display = gr.Text(label="Dish Name")
84
+ portion_row = gr.Row(visible=False) # Portion size buttons section
85
+ portion_image = gr.Image(label="Portion Size Image")
86
+ spice_row = gr.Row(visible=False) # Spice level buttons section
87
 
88
+ # Portion size buttons
89
  with portion_row:
90
  portion_buttons = []
91
  for portion in ["small", "medium", "large"]:
92
  portion_buttons.append(gr.Button(value=portion.capitalize()))
93
 
94
+ # Spice level buttons
95
+ with spice_row:
96
+ spice_buttons = []
97
+ for spice in ["Mild", "Medium", "Spicy"]:
98
+ spice_buttons.append(gr.Button(value=spice))
99
+
100
  # Link dish buttons to display the selected dish
101
+ def create_dish_click_handler(dish):
102
+ return lambda: display_dish(dish)
103
+
104
+ for dish in dish_data.keys():
105
+ button = gr.Button(value=dish, visible=False)
 
106
  button.click(
107
+ fn=create_dish_click_handler(dish),
108
+ inputs=[],
109
+ outputs=[main_image, dish_name_display, portion_row, spice_row],
110
  )
111
 
112
  # Link portion buttons to display the portion image
 
117
  outputs=portion_image,
118
  )
119
 
120
+ # Link spice level buttons to display the spice level
121
+ for spice_button, spice in zip(spice_buttons, ["Mild", "Medium", "Spicy"]):
122
+ spice_button.click(
123
+ fn=spice_level_selection,
124
+ inputs=[gr.Textbox(value=spice, visible=False)],
125
+ outputs=dish_name_display
126
+ )
127
+
128
  # Launch the Gradio app
129
  demo.launch()