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