Spaces:
Runtime error
Runtime error
Added resize option changed outputs to jpg
Browse files
app.py
CHANGED
|
@@ -16,9 +16,25 @@ def get_number_of_profiles_and_labels(profiles_json):
|
|
| 16 |
profiles = default_profiles
|
| 17 |
return len(profiles), list(profiles.keys())
|
| 18 |
|
| 19 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
image = Image.open(image)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# Override parameters based on checkbox state
|
| 23 |
chroma_override = chroma_override_value if chroma_override_flag else None
|
| 24 |
blur_override = blur_override_value if blur_override_flag else None
|
|
@@ -29,8 +45,9 @@ def gradio_interface(image, profiles_json, selected_profile, chroma_override_fla
|
|
| 29 |
|
| 30 |
output_images = []
|
| 31 |
for img in processed_images:
|
| 32 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".
|
| 33 |
-
img
|
|
|
|
| 34 |
output_images.append(tmpfile.name)
|
| 35 |
return output_images
|
| 36 |
|
|
@@ -60,6 +77,10 @@ iface = gr.Interface(
|
|
| 60 |
|
| 61 |
gr.Checkbox(label="Cross Process"),
|
| 62 |
gr.Dropdown(choices=["color", "advanced", "both", "auto"], value="auto", label="Curve Type"),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
],
|
| 64 |
outputs=dynamic_outputs(None),
|
| 65 |
title="Film Simulation",
|
|
|
|
| 16 |
profiles = default_profiles
|
| 17 |
return len(profiles), list(profiles.keys())
|
| 18 |
|
| 19 |
+
def resize_image(image, longer_side):
|
| 20 |
+
# Calculate the resize dimensions while maintaining the aspect ratio
|
| 21 |
+
width, height = image.size
|
| 22 |
+
if width > height:
|
| 23 |
+
new_width = longer_side
|
| 24 |
+
new_height = int((longer_side / width) * height)
|
| 25 |
+
else:
|
| 26 |
+
new_height = longer_side
|
| 27 |
+
new_width = int((longer_side / height) * width)
|
| 28 |
+
|
| 29 |
+
return image.resize((new_width, new_height), Image.ANTIALIAS)
|
| 30 |
+
|
| 31 |
+
def gradio_interface(image, profiles_json, selected_profile, chroma_override_flag, chroma_override_value, blur_override_flag, blur_override_value, color_temp_flag, color_temp_value, cross_process_flag, curve_type, resize_flag, resize_value):
|
| 32 |
image = Image.open(image)
|
| 33 |
|
| 34 |
+
# Resize the image if the resize option is enabled
|
| 35 |
+
if resize_flag:
|
| 36 |
+
image = resize_image(image, resize_value)
|
| 37 |
+
|
| 38 |
# Override parameters based on checkbox state
|
| 39 |
chroma_override = chroma_override_value if chroma_override_flag else None
|
| 40 |
blur_override = blur_override_value if blur_override_flag else None
|
|
|
|
| 45 |
|
| 46 |
output_images = []
|
| 47 |
for img in processed_images:
|
| 48 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmpfile:
|
| 49 |
+
img = img.convert("RGB") # Convert to RGB if the image has transparency
|
| 50 |
+
img.save(tmpfile.name, format="JPEG", quality=90) # Save as JPG with quality setting
|
| 51 |
output_images.append(tmpfile.name)
|
| 52 |
return output_images
|
| 53 |
|
|
|
|
| 77 |
|
| 78 |
gr.Checkbox(label="Cross Process"),
|
| 79 |
gr.Dropdown(choices=["color", "advanced", "both", "auto"], value="auto", label="Curve Type"),
|
| 80 |
+
|
| 81 |
+
# Resize option
|
| 82 |
+
gr.Checkbox(label="Resize Image (Longer Side)"),
|
| 83 |
+
gr.Slider(256, 4096, step=16, value=1024, label="Resize Value"),
|
| 84 |
],
|
| 85 |
outputs=dynamic_outputs(None),
|
| 86 |
title="Film Simulation",
|