Rammohan0504 commited on
Commit
704a7ec
·
verified ·
1 Parent(s): 50729b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -57
app.py CHANGED
@@ -1,59 +1,55 @@
1
  import gradio as gr
2
 
3
- def display_portion_image(dish, portion):
4
- # Define a mapping of images for each portion size
5
- images = {
6
- "Pizza": {
7
- "Small": "https://example.com/pizza_small.jpg",
8
- "Medium": "https://example.com/pizza_medium.jpg",
9
- "Large": "https://example.com/pizza_large.jpg",
10
- },
11
- "Burger": {
12
- "Small": "https://example.com/burger_small.jpg",
13
- "Medium": "https://example.com/burger_medium.jpg",
14
- "Large": "https://example.com/burger_large.jpg",
15
- },
16
- }
17
-
18
- # Fetch the corresponding image based on dish and portion size
19
- if dish in images and portion in images[dish]:
20
- image_url = images[dish][portion]
21
- else:
22
- image_url = "https://example.com/default_image.jpg" # Default image if no match found
23
-
24
- return image_url
25
-
26
- # Define the interface
27
- def main():
28
- with gr.Blocks() as app:
29
- gr.Markdown("""
30
- ### Food Selection with Portion Sizes
31
- Select a dish and a portion size to view the corresponding image.
32
- """)
33
-
34
- dish = gr.Dropdown(
35
- label="Select Dish",
36
- choices=["Pizza", "Burger"],
37
- value="Pizza"
38
- )
39
-
40
- portion = gr.Radio(
41
- label="Select Portion Size",
42
- choices=["Small", "Medium", "Large"],
43
- value="Medium"
44
- )
45
-
46
- image_output = gr.Image(type="filepath", label="Dish Image")
47
-
48
-
49
- # Link inputs and outputs
50
- gr.Button("Show Image").click(
51
- display_portion_image,
52
- inputs=[dish, portion],
53
- outputs=image_output
54
- )
55
-
56
- app.launch()
57
-
58
- if __name__ == "__main__":
59
- main()
 
1
  import gradio as gr
2
 
3
+ # Dictionary to store images for each dish and portion size
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",
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 display the main image and portion size image
26
+ def display_images(dish, portion):
27
+ if dish in dish_data:
28
+ main_image = dish_data[dish]["main"]
29
+ portion_image = dish_data[dish].get(portion, main_image) # Default to main image if portion not found
30
+ return main_image, portion_image
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("### Select a Dish and Portion Size")
39
+
40
+ with gr.Row():
41
+ dish_dropdown = gr.Dropdown(choices=dish_list, label="Select Dish")
42
+ portion_dropdown = gr.Dropdown(choices=portion_sizes, label="Select Portion Size")
43
+
44
+ with gr.Row():
45
+ main_image_display = gr.Image(label="Main Image")
46
+ portion_image_display = gr.Image(label="Portion Image")
47
+
48
+ # Button to trigger image display
49
+ submit_button = gr.Button("Show Images")
50
+
51
+ # Update images based on selections
52
+ submit_button.click(display_images, inputs=[dish_dropdown, portion_dropdown], outputs=[main_image_display, portion_image_display])
53
+
54
+ # Launch the application
55
+ demo.launch()