Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
# Define available dishes and their portion sizes with image paths
|
| 3 |
dish_data = {
|
| 4 |
"Pizza": {
|
|
@@ -24,9 +25,9 @@ dish_data = {
|
|
| 24 |
# Function to handle displaying the main dish image and enabling portion buttons
|
| 25 |
def display_dish(dish):
|
| 26 |
if dish not in dish_data:
|
| 27 |
-
return None, dish, False
|
| 28 |
main_image = dish_data[dish]["main"]
|
| 29 |
-
return main_image, dish, True
|
| 30 |
|
| 31 |
# Function to handle displaying the portion size image
|
| 32 |
def display_portion(dish, portion):
|
|
@@ -44,17 +45,16 @@ with gr.Blocks() as demo:
|
|
| 44 |
selected_dish = gr.State() # Store the selected dish
|
| 45 |
main_image = gr.Image(label="Dish Image")
|
| 46 |
dish_name_display = gr.Text(label="Dish Name")
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
dish_buttons = []
|
| 50 |
for dish, data in dish_data.items():
|
| 51 |
dish_buttons.append(gr.Button(value=dish, elem_id=f"button_{dish}"))
|
| 52 |
|
| 53 |
-
# Section to display portion size buttons
|
| 54 |
-
with
|
| 55 |
-
gr.Markdown("## Select Portion Size")
|
| 56 |
portion_buttons = []
|
| 57 |
-
portion_image = gr.Image(label="Portion Size Image")
|
| 58 |
for portion in ["small", "medium", "large"]:
|
| 59 |
portion_buttons.append(gr.Button(value=portion.capitalize()))
|
| 60 |
|
|
@@ -63,7 +63,7 @@ with gr.Blocks() as demo:
|
|
| 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,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
|
| 3 |
# Define available dishes and their portion sizes with image paths
|
| 4 |
dish_data = {
|
| 5 |
"Pizza": {
|
|
|
|
| 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):
|
|
|
|
| 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 |
|
|
|
|
| 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,
|