Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,71 +1,58 @@
|
|
| 1 |
-
import fitz # PyMuPDF
|
| 2 |
import gradio as gr
|
| 3 |
-
from PIL import Image, ImageEnhance, ImageFilter
|
| 4 |
-
import io
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
gr.Number(label="Width (inches)", value=4.0),
|
| 63 |
-
gr.Slider(minimum=0.5, maximum=2, step=0.1, value=1.0, label="Brightness"),
|
| 64 |
-
],
|
| 65 |
-
outputs="image",
|
| 66 |
-
title="Plate Design Creation - Convert & Adjust PDF Page",
|
| 67 |
-
description="Upload a PDF containing a technical diagram or nameplate. Adjust the dimensions and brightness for optimal clarity."
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
# Launch the interface
|
| 71 |
-
iface.launch()
|
|
|
|
|
|
|
| 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="auto", label="Dish Image")
|
| 47 |
+
|
| 48 |
+
# Link inputs and outputs
|
| 49 |
+
gr.Button("Show Image").click(
|
| 50 |
+
display_portion_image,
|
| 51 |
+
inputs=[dish, portion],
|
| 52 |
+
outputs=image_output
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
app.launch()
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|