Spaces:
Runtime error
Runtime error
lemonaddie
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -13,242 +13,259 @@ from gradio_imageslider import ImageSlider
|
|
13 |
|
14 |
import spaces
|
15 |
|
16 |
-
def
|
17 |
-
|
18 |
-
path_input,
|
19 |
-
ensemble_size,
|
20 |
-
denoise_steps,
|
21 |
-
processing_res,
|
22 |
-
path_out_16bit=None,
|
23 |
-
path_out_fp32=None,
|
24 |
-
path_out_vis=None,
|
25 |
-
):
|
26 |
-
|
27 |
-
if path_out_vis is not None:
|
28 |
-
return (
|
29 |
-
[path_out_16bit, path_out_vis],
|
30 |
-
[path_out_16bit, path_out_fp32, path_out_vis],
|
31 |
-
)
|
32 |
-
|
33 |
-
input_image = Image.open(path_input)
|
34 |
-
|
35 |
-
pipe_out = pipe(
|
36 |
-
input_image,
|
37 |
-
denoising_steps=denoise_steps,
|
38 |
-
ensemble_size=ensemble_size,
|
39 |
-
processing_res=processing_res,
|
40 |
-
batch_size=1 if processing_res == 0 else 0,
|
41 |
-
guidance_scale=3,
|
42 |
-
domain="indoor",
|
43 |
-
show_progress_bar=True,
|
44 |
-
)
|
45 |
-
|
46 |
-
depth_pred = pipe_out.depth_np
|
47 |
-
depth_colored = pipe_out.depth_colored
|
48 |
-
depth_16bit = (depth_pred * 65535.0).astype(np.uint16)
|
49 |
-
|
50 |
-
path_output_dir = os.path.splitext(path_input)[0] + "_output"
|
51 |
-
os.makedirs(path_output_dir, exist_ok=True)
|
52 |
-
|
53 |
-
name_base = os.path.splitext(os.path.basename(path_input))[0]
|
54 |
-
path_out_fp32 = os.path.join(path_output_dir, f"{name_base}_depth_fp32.npy")
|
55 |
-
path_out_16bit = os.path.join(path_output_dir, f"{name_base}_depth_16bit.png")
|
56 |
-
path_out_vis = os.path.join(path_output_dir, f"{name_base}_depth_colored.png")
|
57 |
-
|
58 |
-
np.save(path_out_fp32, depth_pred)
|
59 |
-
Image.fromarray(depth_16bit).save(path_out_16bit, mode="I;16")
|
60 |
-
depth_colored.save(path_out_vis)
|
61 |
-
|
62 |
-
return (
|
63 |
-
[path_out_16bit, path_out_vis],
|
64 |
-
[path_out_16bit, path_out_fp32, path_out_vis],
|
65 |
-
)
|
66 |
-
|
67 |
|
68 |
@spaces.GPU
|
69 |
def run_demo_server(pipe):
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
|
253 |
|
254 |
def main():
|
|
|
13 |
|
14 |
import spaces
|
15 |
|
16 |
+
def identity(img):
|
17 |
+
return img, img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
@spaces.GPU
|
20 |
def run_demo_server(pipe):
|
21 |
+
title = "Geowizard"
|
22 |
+
description = "Gradio demo for Geowizard."
|
23 |
+
|
24 |
+
examples = ["files/bee.jpg"]
|
25 |
+
|
26 |
+
gr.Interface(
|
27 |
+
depth_normal,
|
28 |
+
inputs=[gr.Image(type='pil', label="Original Image"),
|
29 |
+
outputs=[gr.Image(type="pil",label="Output Depth"), gr.Image(type="pil",label="Output Normal")],
|
30 |
+
title=title, description=description, article='1', examples=examples, analytics_enabled=False).launch()
|
31 |
+
|
32 |
+
|
33 |
+
# def process(
|
34 |
+
# pipe,
|
35 |
+
# path_input,
|
36 |
+
# ensemble_size,
|
37 |
+
# denoise_steps,
|
38 |
+
# processing_res,
|
39 |
+
# path_out_16bit=None,
|
40 |
+
# path_out_fp32=None,
|
41 |
+
# path_out_vis=None,
|
42 |
+
# ):
|
43 |
+
|
44 |
+
# if path_out_vis is not None:
|
45 |
+
# return (
|
46 |
+
# [path_out_16bit, path_out_vis],
|
47 |
+
# [path_out_16bit, path_out_fp32, path_out_vis],
|
48 |
+
# )
|
49 |
+
|
50 |
+
# input_image = Image.open(path_input)
|
51 |
+
|
52 |
+
# pipe_out = pipe(
|
53 |
+
# input_image,
|
54 |
+
# denoising_steps=denoise_steps,
|
55 |
+
# ensemble_size=ensemble_size,
|
56 |
+
# processing_res=processing_res,
|
57 |
+
# batch_size=1 if processing_res == 0 else 0,
|
58 |
+
# guidance_scale=3,
|
59 |
+
# domain="indoor",
|
60 |
+
# show_progress_bar=True,
|
61 |
+
# )
|
62 |
+
|
63 |
+
# depth_pred = pipe_out.depth_np
|
64 |
+
# depth_colored = pipe_out.depth_colored
|
65 |
+
# depth_16bit = (depth_pred * 65535.0).astype(np.uint16)
|
66 |
+
|
67 |
+
# path_output_dir = os.path.splitext(path_input)[0] + "_output"
|
68 |
+
# os.makedirs(path_output_dir, exist_ok=True)
|
69 |
+
|
70 |
+
# name_base = os.path.splitext(os.path.basename(path_input))[0]
|
71 |
+
# path_out_fp32 = os.path.join(path_output_dir, f"{name_base}_depth_fp32.npy")
|
72 |
+
# path_out_16bit = os.path.join(path_output_dir, f"{name_base}_depth_16bit.png")
|
73 |
+
# path_out_vis = os.path.join(path_output_dir, f"{name_base}_depth_colored.png")
|
74 |
+
|
75 |
+
# np.save(path_out_fp32, depth_pred)
|
76 |
+
# Image.fromarray(depth_16bit).save(path_out_16bit, mode="I;16")
|
77 |
+
# depth_colored.save(path_out_vis)
|
78 |
+
|
79 |
+
# return (
|
80 |
+
# [path_out_16bit, path_out_vis],
|
81 |
+
# [path_out_16bit, path_out_fp32, path_out_vis],
|
82 |
+
# )
|
83 |
+
|
84 |
+
|
85 |
+
# @spaces.GPU
|
86 |
+
# def run_demo_server(pipe):
|
87 |
+
# process_pipe = functools.partial(process, pipe)
|
88 |
+
# os.environ["GRADIO_ALLOW_FLAGGING"] = "never"
|
89 |
+
|
90 |
+
# with gr.Blocks(
|
91 |
+
# analytics_enabled=False,
|
92 |
+
# title="GeoWizard Depth and Normal Estimation",
|
93 |
+
# css="""
|
94 |
+
# #download {
|
95 |
+
# height: 118px;
|
96 |
+
# }
|
97 |
+
# .slider .inner {
|
98 |
+
# width: 5px;
|
99 |
+
# background: #FFF;
|
100 |
+
# }
|
101 |
+
# .viewport {
|
102 |
+
# aspect-ratio: 4/3;
|
103 |
+
# }
|
104 |
+
# """,
|
105 |
+
# ) as demo:
|
106 |
+
# gr.Markdown(
|
107 |
+
# """
|
108 |
+
# <h1 align="center">Geowizard Depth & Normal Estimation</h1>
|
109 |
+
# """
|
110 |
+
# )
|
111 |
+
|
112 |
+
# with gr.Row():
|
113 |
+
# with gr.Column():
|
114 |
+
# input_image = gr.Image(
|
115 |
+
# label="Input Image",
|
116 |
+
# type="filepath",
|
117 |
+
# )
|
118 |
+
# with gr.Accordion("Advanced options", open=False):
|
119 |
+
# domain = gr.Radio(
|
120 |
+
# [
|
121 |
+
# ("Outdoor", "outdoor"),
|
122 |
+
# ("Indoor", "indoor"),
|
123 |
+
# ("Object", "object"),
|
124 |
+
# ],
|
125 |
+
# label="Data Domain",
|
126 |
+
# value="indoor",
|
127 |
+
# )
|
128 |
+
# cfg_scale = gr.Slider(
|
129 |
+
# label="Classifier Free Guidance Scale",
|
130 |
+
# minimum=1,
|
131 |
+
# maximum=5,
|
132 |
+
# step=1,
|
133 |
+
# value=3,
|
134 |
+
# )
|
135 |
+
# denoise_steps = gr.Slider(
|
136 |
+
# label="Number of denoising steps",
|
137 |
+
# minimum=1,
|
138 |
+
# maximum=20,
|
139 |
+
# step=1,
|
140 |
+
# value=2,
|
141 |
+
# )
|
142 |
+
# ensemble_size = gr.Slider(
|
143 |
+
# label="Ensemble size",
|
144 |
+
# minimum=1,
|
145 |
+
# maximum=15,
|
146 |
+
# step=1,
|
147 |
+
# value=1,
|
148 |
+
# )
|
149 |
+
# processing_res = gr.Radio(
|
150 |
+
# [
|
151 |
+
# ("Native", 0),
|
152 |
+
# ("Recommended", 768),
|
153 |
+
# ],
|
154 |
+
# label="Processing resolution",
|
155 |
+
# value=768,
|
156 |
+
# )
|
157 |
+
# input_output_16bit = gr.File(
|
158 |
+
# label="Predicted depth (16-bit)",
|
159 |
+
# visible=False,
|
160 |
+
# )
|
161 |
+
# input_output_fp32 = gr.File(
|
162 |
+
# label="Predicted depth (32-bit)",
|
163 |
+
# visible=False,
|
164 |
+
# )
|
165 |
+
# input_output_vis = gr.File(
|
166 |
+
# label="Predicted depth (red-near, blue-far)",
|
167 |
+
# visible=False,
|
168 |
+
# )
|
169 |
+
# with gr.Row():
|
170 |
+
# submit_btn = gr.Button(value="Compute", variant="primary")
|
171 |
+
# clear_btn = gr.Button(value="Clear")
|
172 |
+
# with gr.Column():
|
173 |
+
# output_slider = ImageSlider(
|
174 |
+
# label="Predicted depth (red-near, blue-far)",
|
175 |
+
# type="filepath",
|
176 |
+
# show_download_button=True,
|
177 |
+
# show_share_button=True,
|
178 |
+
# interactive=False,
|
179 |
+
# elem_classes="slider",
|
180 |
+
# position=0.25,
|
181 |
+
# )
|
182 |
+
# files = gr.Files(
|
183 |
+
# label="Depth outputs",
|
184 |
+
# elem_id="download",
|
185 |
+
# interactive=False,
|
186 |
+
# )
|
187 |
+
|
188 |
+
# blocks_settings_depth = [ensemble_size, denoise_steps, processing_res]
|
189 |
+
# blocks_settings = blocks_settings_depth
|
190 |
+
# map_id_to_default = {b._id: b.value for b in blocks_settings}
|
191 |
+
|
192 |
+
# inputs = [
|
193 |
+
# input_image,
|
194 |
+
# ensemble_size,
|
195 |
+
# denoise_steps,
|
196 |
+
# processing_res,
|
197 |
+
# input_output_16bit,
|
198 |
+
# input_output_fp32,
|
199 |
+
# input_output_vis,
|
200 |
+
# ]
|
201 |
+
# outputs = [
|
202 |
+
# submit_btn,
|
203 |
+
# input_image,
|
204 |
+
# output_slider,
|
205 |
+
# files,
|
206 |
+
# ]
|
207 |
+
|
208 |
+
# def submit_depth_fn(*args):
|
209 |
+
# out = list(process_pipe(*args))
|
210 |
+
# out = [gr.Button(interactive=False), gr.Image(interactive=False)] + out
|
211 |
+
# return out
|
212 |
+
|
213 |
+
# submit_btn.click(
|
214 |
+
# fn=submit_depth_fn,
|
215 |
+
# inputs=inputs,
|
216 |
+
# outputs=outputs,
|
217 |
+
# concurrency_limit=1,
|
218 |
+
# )
|
219 |
+
|
220 |
+
# gr.Examples(
|
221 |
+
# fn=submit_depth_fn,
|
222 |
+
# examples=[
|
223 |
+
# [
|
224 |
+
# "files/bee.jpg",
|
225 |
+
# 10, # ensemble_size
|
226 |
+
# 10, # denoise_steps
|
227 |
+
# 768, # processing_res
|
228 |
+
# "files/bee_depth_16bit.png",
|
229 |
+
# "files/bee_depth_fp32.npy",
|
230 |
+
# "files/bee_depth_colored.png",
|
231 |
+
# ],
|
232 |
+
# ],
|
233 |
+
# inputs=inputs,
|
234 |
+
# outputs=outputs,
|
235 |
+
# cache_examples=True,
|
236 |
+
# )
|
237 |
+
|
238 |
+
# def clear_fn():
|
239 |
+
# out = []
|
240 |
+
# for b in blocks_settings:
|
241 |
+
# out.append(map_id_to_default[b._id])
|
242 |
+
# out += [
|
243 |
+
# gr.Button(interactive=True),
|
244 |
+
# gr.Image(value=None, interactive=True),
|
245 |
+
# None, None, None, None, None, None, None,
|
246 |
+
# ]
|
247 |
+
# return out
|
248 |
+
|
249 |
+
# clear_btn.click(
|
250 |
+
# fn=clear_fn,
|
251 |
+
# inputs=[],
|
252 |
+
# outputs=blocks_settings + [
|
253 |
+
# submit_btn,
|
254 |
+
# input_image,
|
255 |
+
# input_output_16bit,
|
256 |
+
# input_output_fp32,
|
257 |
+
# input_output_vis,
|
258 |
+
# output_slider,
|
259 |
+
# files,
|
260 |
+
# ],
|
261 |
+
# )
|
262 |
+
|
263 |
+
# demo.queue(
|
264 |
+
# api_open=False,
|
265 |
+
# ).launch(
|
266 |
+
# server_name="0.0.0.0",
|
267 |
+
# server_port=7860,
|
268 |
+
# )
|
269 |
|
270 |
|
271 |
def main():
|