Rammohan0504 commited on
Commit
c22e4be
·
verified ·
1 Parent(s): 8c5b319

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -76,7 +76,7 @@ def display_dishes(category):
76
  def get_dish_details(dish_name):
77
  if dish_name in dish_data:
78
  main_image = dish_data[dish_name]["main"]
79
- return main_image, dish_name, "Select a portion size below:"
80
  return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available."
81
 
82
  # Function to display the portion size image
@@ -104,18 +104,16 @@ with gr.Blocks() as demo:
104
  gr.Markdown("### Available Dishes")
105
  dish_display = gr.HTML(value=display_dishes("ALL"))
106
 
107
- # Dish Details Section
108
- gr.Markdown("### Dish Details")
109
- with gr.Row():
110
  dish_image = gr.Image(label="Dish Image", height=200, width=200)
 
111
  with gr.Column():
112
- dish_name = gr.Textbox(label="Dish Name", interactive=False)
113
- dish_description = gr.Textbox(label="Description", interactive=False)
114
  spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="🌶 Medium")
115
  portion_dropdown = gr.Radio(label="Select Portion Size", choices=["small", "medium", "large"], value="medium")
116
  portion_image = gr.Image(label="Portion Size Image")
117
 
118
- # Place Order Button
119
  place_order_btn = gr.Button("Place Order")
120
  order_status = gr.Textbox(label="Order Status", interactive=False)
121
 
@@ -127,15 +125,16 @@ with gr.Blocks() as demo:
127
  btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
128
  btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
129
 
130
- # Event: Show dish details when a dish is selected
131
  def show_dish_details(dish_name):
132
  image, name, description = get_dish_details(dish_name)
 
133
  return image, name, description
134
 
135
  # Hidden input to receive dish name from JavaScript
136
  selected_dish_name = gr.Textbox(visible=False)
137
  selected_dish_name.change(fn=show_dish_details, inputs=selected_dish_name,
138
- outputs=[dish_image, dish_name, dish_description])
139
 
140
  # Event: Display portion size image
141
  portion_dropdown.change(fn=display_portion, inputs=[selected_dish_name, portion_dropdown], outputs=portion_image)
 
76
  def get_dish_details(dish_name):
77
  if dish_name in dish_data:
78
  main_image = dish_data[dish_name]["main"]
79
+ return main_image, dish_name, "Select a portion size and spice level below:"
80
  return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available."
81
 
82
  # Function to display the portion size image
 
104
  gr.Markdown("### Available Dishes")
105
  dish_display = gr.HTML(value=display_dishes("ALL"))
106
 
107
+ # Popup for Dish Details
108
+ with gr.Modal("Dish Details") as dish_modal:
 
109
  dish_image = gr.Image(label="Dish Image", height=200, width=200)
110
+ dish_name = gr.Textbox(label="Dish Name", interactive=False)
111
  with gr.Column():
 
 
112
  spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="🌶 Medium")
113
  portion_dropdown = gr.Radio(label="Select Portion Size", choices=["small", "medium", "large"], value="medium")
114
  portion_image = gr.Image(label="Portion Size Image")
115
 
116
+ # Place Order Button inside Modal
117
  place_order_btn = gr.Button("Place Order")
118
  order_status = gr.Textbox(label="Order Status", interactive=False)
119
 
 
125
  btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
126
  btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
127
 
128
+ # Event: Show dish details in the modal when a dish is selected
129
  def show_dish_details(dish_name):
130
  image, name, description = get_dish_details(dish_name)
131
+ dish_modal.show()
132
  return image, name, description
133
 
134
  # Hidden input to receive dish name from JavaScript
135
  selected_dish_name = gr.Textbox(visible=False)
136
  selected_dish_name.change(fn=show_dish_details, inputs=selected_dish_name,
137
+ outputs=[dish_image, dish_name, dish_modal])
138
 
139
  # Event: Display portion size image
140
  portion_dropdown.change(fn=display_portion, inputs=[selected_dish_name, portion_dropdown], outputs=portion_image)