Rammohan0504 commited on
Commit
10f6576
·
verified ·
1 Parent(s): 963f7ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -26
app.py CHANGED
@@ -22,66 +22,62 @@ dish_data = {
22
  },
23
  }
24
 
 
 
 
 
 
 
 
 
25
  def display_portion(dish, portion):
26
  if dish not in dish_data:
27
- return None # Handle invalid dish selection
28
  portion_image = dish_data[dish].get(portion, None)
29
  return portion_image
30
 
31
- def display_dish(dish):
32
- if dish not in dish_data:
33
- return None, None
34
- main_image = dish_data[dish]["main"]
35
- return main_image, dish
36
-
37
  # Define the Gradio interface
38
  with gr.Blocks() as demo:
39
  gr.Markdown("# Food Ordering System")
40
 
41
- # Section to display dishes as clickable images
42
  with gr.Row():
 
 
 
 
 
43
  dish_buttons = []
44
  for dish, data in dish_data.items():
45
- with gr.Column():
46
- button = gr.Button(value=dish, elem_id=f"button_{dish}")
47
- dish_buttons.append((button, dish))
48
-
49
- # Section to display the main image of the selected dish
50
- selected_dish = gr.State() # Store the selected dish name
51
- main_image = gr.Image(label="Dish Image")
52
- dish_name_display = gr.Text(label="Dish Name")
53
 
54
  # Section to display portion size buttons and corresponding image
55
  with gr.Row(visible=False) as portion_row:
56
  gr.Markdown("## Select Portion Size")
57
  portion_buttons = []
58
- for portion in ["small", "medium", "large"]:
59
- portion_button = gr.Button(value=portion.capitalize())
60
- portion_buttons.append(portion_button)
61
-
62
  portion_image = gr.Image(label="Portion Size Image")
 
 
63
 
64
  # Link dish buttons to display the selected dish
65
- for button, dish in dish_buttons:
66
  button.click(
67
  fn=display_dish,
68
  inputs=[gr.Textbox(value=dish, visible=False)],
69
- outputs=[main_image, dish_name_display]
70
  )
71
  button.click(
72
  fn=lambda x: x,
73
  inputs=[gr.Textbox(value=dish, visible=False)],
74
- outputs=[selected_dish],
75
- show_progress=False
76
  )
77
- button.click(None, [], [], _js=f"() => document.querySelector('[visible=false]').style.display = 'flex';")
78
 
79
  # Link portion buttons to display the portion image
80
  for portion_button, portion in zip(portion_buttons, ["small", "medium", "large"]):
81
  portion_button.click(
82
  fn=display_portion,
83
  inputs=[selected_dish, gr.Textbox(value=portion, visible=False)],
84
- outputs=portion_image
85
  )
86
 
87
  # Launch the Gradio app
 
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, False
29
+ main_image = dish_data[dish]["main"]
30
+ return main_image, dish, 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_visible = gr.State(value=False)
49
+
50
  dish_buttons = []
51
  for dish, data in dish_data.items():
52
+ dish_buttons.append(gr.Button(value=dish, elem_id=f"button_{dish}"))
 
 
 
 
 
 
 
53
 
54
  # Section to display portion size buttons and corresponding image
55
  with gr.Row(visible=False) as portion_row:
56
  gr.Markdown("## Select Portion Size")
57
  portion_buttons = []
 
 
 
 
58
  portion_image = gr.Image(label="Portion Size Image")
59
+ for portion in ["small", "medium", "large"]:
60
+ portion_buttons.append(gr.Button(value=portion.capitalize()))
61
 
62
  # Link dish buttons to display the selected dish
63
+ for button, dish in zip(dish_buttons, dish_data.keys()):
64
  button.click(
65
  fn=display_dish,
66
  inputs=[gr.Textbox(value=dish, visible=False)],
67
+ outputs=[main_image, dish_name_display, portion_row.visible],
68
  )
69
  button.click(
70
  fn=lambda x: x,
71
  inputs=[gr.Textbox(value=dish, visible=False)],
72
+ outputs=selected_dish,
 
73
  )
 
74
 
75
  # Link portion buttons to display the portion image
76
  for portion_button, portion in zip(portion_buttons, ["small", "medium", "large"]):
77
  portion_button.click(
78
  fn=display_portion,
79
  inputs=[selected_dish, gr.Textbox(value=portion, visible=False)],
80
+ outputs=portion_image,
81
  )
82
 
83
  # Launch the Gradio app