Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
#
|
| 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",
|
|
@@ -22,34 +22,47 @@ dish_data = {
|
|
| 22 |
},
|
| 23 |
}
|
| 24 |
|
| 25 |
-
# Function to display
|
| 26 |
def display_images(dish, portion):
|
| 27 |
-
if dish in dish_data:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
return
|
| 32 |
-
|
| 33 |
-
# Gradio interface
|
| 34 |
-
dish_list = list(dish_data.keys())
|
| 35 |
-
portion_sizes = ["small", "medium", "large"]
|
| 36 |
|
|
|
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
-
gr.Markdown("
|
| 39 |
-
|
|
|
|
| 40 |
with gr.Row():
|
| 41 |
-
dish_dropdown = gr.Dropdown(
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
with gr.Row():
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
# Launch the
|
| 55 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Define available dishes and their portion sizes with image paths
|
| 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 |
},
|
| 11 |
"Burger": {
|
| 12 |
"main": "images/burger_main.jpg",
|
|
|
|
| 22 |
},
|
| 23 |
}
|
| 24 |
|
| 25 |
+
# Function to display images dynamically
|
| 26 |
def display_images(dish, portion):
|
| 27 |
+
if dish not in dish_data:
|
| 28 |
+
return None, None # Handle invalid dish selection
|
| 29 |
+
main_image = dish_data[dish]["main"]
|
| 30 |
+
portion_image = dish_data[dish].get(portion, None)
|
| 31 |
+
return main_image, portion_image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
# Define the Gradio interface
|
| 34 |
with gr.Blocks() as demo:
|
| 35 |
+
gr.Markdown("# Food Ordering System with Portion Sizes")
|
| 36 |
+
|
| 37 |
+
# Dish selection dropdown
|
| 38 |
with gr.Row():
|
| 39 |
+
dish_dropdown = gr.Dropdown(
|
| 40 |
+
choices=list(dish_data.keys()),
|
| 41 |
+
label="Select Dish",
|
| 42 |
+
value="Pizza"
|
| 43 |
+
)
|
| 44 |
+
portion_dropdown = gr.Dropdown(
|
| 45 |
+
choices=["small", "medium", "large"],
|
| 46 |
+
label="Select Portion Size",
|
| 47 |
+
value="small"
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
# Image display section
|
| 51 |
with gr.Row():
|
| 52 |
+
main_image = gr.Image(label="Main Image")
|
| 53 |
+
portion_image = gr.Image(label="Portion Size Image")
|
| 54 |
+
|
| 55 |
+
# Link dropdowns to the image display function
|
| 56 |
+
dish_dropdown.change(
|
| 57 |
+
fn=display_images,
|
| 58 |
+
inputs=[dish_dropdown, portion_dropdown],
|
| 59 |
+
outputs=[main_image, portion_image]
|
| 60 |
+
)
|
| 61 |
+
portion_dropdown.change(
|
| 62 |
+
fn=display_images,
|
| 63 |
+
inputs=[dish_dropdown, portion_dropdown],
|
| 64 |
+
outputs=[main_image, portion_image]
|
| 65 |
+
)
|
| 66 |
|
| 67 |
+
# Launch the Gradio app
|
| 68 |
demo.launch()
|