Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -60,26 +60,33 @@ def resize_image(input_image, width, height):
|
|
60 |
temp_file.close()
|
61 |
return Image.open(temp_file.name)
|
62 |
|
63 |
-
def process_image(
|
64 |
-
|
|
|
65 |
|
66 |
-
|
67 |
-
original_image =
|
68 |
-
|
69 |
-
if adjust_dpi:
|
70 |
-
original_image = muda_dpi(np.array(original_image), dpi)
|
71 |
|
72 |
-
|
73 |
-
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
iface = gr.Interface(
|
80 |
fn=process_image,
|
81 |
inputs=[
|
82 |
-
gr.
|
83 |
gr.Checkbox(label="Enhance Image (ESRGAN)"),
|
84 |
gr.Radio(['2x', '4x', '8x'], type="value", value='2x', label='Resolution model'),
|
85 |
gr.Checkbox(label="Adjust DPI"),
|
@@ -89,11 +96,11 @@ iface = gr.Interface(
|
|
89 |
gr.Number(label="Height", value=512)
|
90 |
],
|
91 |
outputs=[
|
92 |
-
gr.
|
93 |
-
gr.File(label="Download Final
|
94 |
],
|
95 |
title="Image Enhancer",
|
96 |
-
description="Upload
|
97 |
examples=[
|
98 |
["gatuno.JPG"]
|
99 |
]
|
|
|
60 |
temp_file.close()
|
61 |
return Image.open(temp_file.name)
|
62 |
|
63 |
+
def process_image(input_images, enhance, scale, adjust_dpi, dpi, resize, width, height):
|
64 |
+
processed_images = []
|
65 |
+
temp_files = []
|
66 |
|
67 |
+
for input_image in input_images:
|
68 |
+
original_image = Image.fromarray(input_image.astype('uint8'), 'RGB')
|
|
|
|
|
|
|
69 |
|
70 |
+
if enhance:
|
71 |
+
original_image = enhance_image(original_image, scale)
|
72 |
|
73 |
+
if adjust_dpi:
|
74 |
+
original_image = muda_dpi(np.array(original_image), dpi)
|
75 |
+
|
76 |
+
if resize:
|
77 |
+
original_image = resize_image(np.array(original_image), width, height)
|
78 |
+
|
79 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
|
80 |
+
original_image.save(temp_file.name)
|
81 |
+
processed_images.append(original_image)
|
82 |
+
temp_files.append(temp_file.name)
|
83 |
+
|
84 |
+
return processed_images, temp_files
|
85 |
|
86 |
iface = gr.Interface(
|
87 |
fn=process_image,
|
88 |
inputs=[
|
89 |
+
gr.File(label="Upload", type="file", file_count="multiple", optional=False),
|
90 |
gr.Checkbox(label="Enhance Image (ESRGAN)"),
|
91 |
gr.Radio(['2x', '4x', '8x'], type="value", value='2x', label='Resolution model'),
|
92 |
gr.Checkbox(label="Adjust DPI"),
|
|
|
96 |
gr.Number(label="Height", value=512)
|
97 |
],
|
98 |
outputs=[
|
99 |
+
gr.Gallery(label="Final Images"),
|
100 |
+
gr.File(label="Download Final Images", file_count="multiple")
|
101 |
],
|
102 |
title="Image Enhancer",
|
103 |
+
description="Upload images (.jpg, .png), enhance using AI, adjust DPI, resize and download the final results.",
|
104 |
examples=[
|
105 |
["gatuno.JPG"]
|
106 |
]
|