Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,6 @@ import functools
|
|
22 |
import os
|
23 |
import tempfile
|
24 |
|
25 |
-
import diffusers
|
26 |
import gradio as gr
|
27 |
import imageio as imageio
|
28 |
import numpy as np
|
@@ -50,10 +49,7 @@ class Examples(gradio.helpers.Examples):
|
|
50 |
default_seed = 2024
|
51 |
default_batch_size = 1
|
52 |
|
53 |
-
default_image_processing_resolution =
|
54 |
-
|
55 |
-
default_video_num_inference_steps = 10
|
56 |
-
default_video_processing_resolution = 768
|
57 |
default_video_out_max_frames = 60
|
58 |
|
59 |
def process_image_check(path_input):
|
@@ -99,12 +95,10 @@ def process_image(
|
|
99 |
path_output_dir = tempfile.mkdtemp()
|
100 |
path_out_png = os.path.join(path_output_dir, f"{name_base}_delight.png")
|
101 |
input_image = Image.open(path_input)
|
102 |
-
input_image = resize_image(input_image, default_image_processing_resolution)
|
103 |
-
|
104 |
pipe_out = pipe(
|
105 |
input_image,
|
106 |
match_input_resolution=False,
|
107 |
-
processing_resolution=
|
108 |
)
|
109 |
|
110 |
processed_frame = (pipe_out.prediction.clip(-1, 1) + 1) / 2
|
@@ -113,20 +107,6 @@ def process_image(
|
|
113 |
processed_frame.save(path_out_png)
|
114 |
yield [input_image, path_out_png]
|
115 |
|
116 |
-
def center_crop(img):
|
117 |
-
# Open the image file
|
118 |
-
img_width, img_height = img.size
|
119 |
-
crop_width =min(img_width, img_height)
|
120 |
-
# Calculate the cropping box
|
121 |
-
left = (img_width - crop_width) / 2
|
122 |
-
top = (img_height - crop_width) / 2
|
123 |
-
right = (img_width + crop_width) / 2
|
124 |
-
bottom = (img_height + crop_width) / 2
|
125 |
-
|
126 |
-
# Crop the image
|
127 |
-
img_cropped = img.crop((left, top, right, bottom))
|
128 |
-
return img_cropped
|
129 |
-
|
130 |
def process_video(
|
131 |
pipe,
|
132 |
path_input,
|
@@ -143,7 +123,7 @@ def process_video(
|
|
143 |
print(f"Processing video {name_base}{name_ext}")
|
144 |
|
145 |
path_output_dir = tempfile.mkdtemp()
|
146 |
-
path_out_vis = os.path.join(path_output_dir, f"{name_base}
|
147 |
|
148 |
init_latents = None
|
149 |
reader, writer = None, None
|
@@ -170,11 +150,11 @@ def process_video(
|
|
170 |
break
|
171 |
|
172 |
frame_pil = Image.fromarray(frame)
|
173 |
-
# frame_pil = center_crop(frame_pil)
|
174 |
pipe_out = pipe(
|
175 |
frame_pil,
|
176 |
match_input_resolution=False,
|
177 |
-
latents=init_latents
|
|
|
178 |
)
|
179 |
|
180 |
if init_latents is None:
|
@@ -212,7 +192,7 @@ def run_demo_server(pipe):
|
|
212 |
|
213 |
with gr.Blocks(
|
214 |
theme=gradio_theme,
|
215 |
-
title="
|
216 |
css="""
|
217 |
#download {
|
218 |
height: 118px;
|
@@ -256,7 +236,7 @@ def run_demo_server(pipe):
|
|
256 |
) as demo:
|
257 |
gr.Markdown(
|
258 |
"""
|
259 |
-
# StableDelight:
|
260 |
<p align="center">
|
261 |
"""
|
262 |
)
|
@@ -271,7 +251,7 @@ def run_demo_server(pipe):
|
|
271 |
)
|
272 |
with gr.Row():
|
273 |
image_submit_btn = gr.Button(
|
274 |
-
value="
|
275 |
)
|
276 |
image_reset_btn = gr.Button(value="Reset")
|
277 |
with gr.Column():
|
|
|
22 |
import os
|
23 |
import tempfile
|
24 |
|
|
|
25 |
import gradio as gr
|
26 |
import imageio as imageio
|
27 |
import numpy as np
|
|
|
49 |
default_seed = 2024
|
50 |
default_batch_size = 1
|
51 |
|
52 |
+
default_image_processing_resolution = 2048
|
|
|
|
|
|
|
53 |
default_video_out_max_frames = 60
|
54 |
|
55 |
def process_image_check(path_input):
|
|
|
95 |
path_output_dir = tempfile.mkdtemp()
|
96 |
path_out_png = os.path.join(path_output_dir, f"{name_base}_delight.png")
|
97 |
input_image = Image.open(path_input)
|
|
|
|
|
98 |
pipe_out = pipe(
|
99 |
input_image,
|
100 |
match_input_resolution=False,
|
101 |
+
processing_resolution=default_image_processing_resolution
|
102 |
)
|
103 |
|
104 |
processed_frame = (pipe_out.prediction.clip(-1, 1) + 1) / 2
|
|
|
107 |
processed_frame.save(path_out_png)
|
108 |
yield [input_image, path_out_png]
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
def process_video(
|
111 |
pipe,
|
112 |
path_input,
|
|
|
123 |
print(f"Processing video {name_base}{name_ext}")
|
124 |
|
125 |
path_output_dir = tempfile.mkdtemp()
|
126 |
+
path_out_vis = os.path.join(path_output_dir, f"{name_base}_delight.mp4")
|
127 |
|
128 |
init_latents = None
|
129 |
reader, writer = None, None
|
|
|
150 |
break
|
151 |
|
152 |
frame_pil = Image.fromarray(frame)
|
|
|
153 |
pipe_out = pipe(
|
154 |
frame_pil,
|
155 |
match_input_resolution=False,
|
156 |
+
latents=init_latents,
|
157 |
+
processing_resolution=default_image_processing_resolution
|
158 |
)
|
159 |
|
160 |
if init_latents is None:
|
|
|
192 |
|
193 |
with gr.Blocks(
|
194 |
theme=gradio_theme,
|
195 |
+
title="Stable Delight Estimation",
|
196 |
css="""
|
197 |
#download {
|
198 |
height: 118px;
|
|
|
236 |
) as demo:
|
237 |
gr.Markdown(
|
238 |
"""
|
239 |
+
# StableDelight: Removing Reflections from Textured Surfaces in a Single Image
|
240 |
<p align="center">
|
241 |
"""
|
242 |
)
|
|
|
251 |
)
|
252 |
with gr.Row():
|
253 |
image_submit_btn = gr.Button(
|
254 |
+
value="Delightning", variant="primary"
|
255 |
)
|
256 |
image_reset_btn = gr.Button(value="Reset")
|
257 |
with gr.Column():
|