Spaces:
Runtime error
Runtime error
lemonaddie
commited on
Delete app1.py
Browse files
app1.py
DELETED
@@ -1,173 +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 |
-
import fire
|
17 |
-
|
18 |
-
REPO_URL = "https://github.com/lemonaddie/geowizard.git"
|
19 |
-
CHECKPOINT = "lemonaddie/Geowizard"
|
20 |
-
REPO_DIR = "geowizard"
|
21 |
-
|
22 |
-
if os.path.isdir(REPO_DIR):
|
23 |
-
shutil.rmtree(REPO_DIR)
|
24 |
-
|
25 |
-
repo = git.Repo.clone_from(REPO_URL, REPO_DIR)
|
26 |
-
sys.path.append(os.path.join(os.getcwd(), REPO_DIR))
|
27 |
-
|
28 |
-
from pipeline.depth_normal_pipeline_clip_cfg import DepthNormalEstimationPipeline
|
29 |
-
|
30 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
31 |
-
pipe = DepthNormalEstimationPipeline.from_pretrained(CHECKPOINT)
|
32 |
-
|
33 |
-
try:
|
34 |
-
import xformers
|
35 |
-
pipe.enable_xformers_memory_efficient_attention()
|
36 |
-
except:
|
37 |
-
pass # run without xformers
|
38 |
-
|
39 |
-
pipe = pipe.to(device)
|
40 |
-
#run_demo_server(pipe)
|
41 |
-
|
42 |
-
@spaces.GPU
|
43 |
-
def depth_normal(img,
|
44 |
-
denoising_steps,
|
45 |
-
ensemble_size,
|
46 |
-
processing_res,
|
47 |
-
guidance_scale,
|
48 |
-
domain):
|
49 |
-
|
50 |
-
#img = img.resize((processing_res, processing_res), Image.Resampling.LANCZOS)
|
51 |
-
pipe_out = pipe(
|
52 |
-
img,
|
53 |
-
denoising_steps=denoising_steps,
|
54 |
-
ensemble_size=ensemble_size,
|
55 |
-
processing_res=processing_res,
|
56 |
-
batch_size=0,
|
57 |
-
guidance_scale=guidance_scale,
|
58 |
-
domain=domain,
|
59 |
-
show_progress_bar=True,
|
60 |
-
)
|
61 |
-
|
62 |
-
depth_colored = pipe_out.depth_colored
|
63 |
-
normal_colored = pipe_out.normal_colored
|
64 |
-
|
65 |
-
return depth_colored, normal_colored
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
def run_demo():
|
70 |
-
|
71 |
-
|
72 |
-
custom_theme = gr.themes.Soft(primary_hue="blue").set(
|
73 |
-
button_secondary_background_fill="*neutral_100",
|
74 |
-
button_secondary_background_fill_hover="*neutral_200")
|
75 |
-
custom_css = '''#disp_image {
|
76 |
-
text-align: center; /* Horizontally center the content */
|
77 |
-
}'''
|
78 |
-
|
79 |
-
_TITLE = '''GeoWizard: Unleashing the Diffusion Priors for 3D Geometry Estimation from a Single Image'''
|
80 |
-
_DESCRIPTION = '''
|
81 |
-
<div>
|
82 |
-
Generate consistent depth and normal from single image. High quality and rich details.
|
83 |
-
<a style="display:inline-block; margin-left: .5em" href='https://github.com/fuxiao0719/GeoWizard/'><img src='https://img.shields.io/github/stars/fuxiao0719/GeoWizard?style=social' /></a>
|
84 |
-
</div>
|
85 |
-
'''
|
86 |
-
_GPU_ID = 0
|
87 |
-
|
88 |
-
with gr.Blocks(title=_TITLE, theme=custom_theme, css=custom_css) as demo:
|
89 |
-
with gr.Row():
|
90 |
-
with gr.Column(scale=1):
|
91 |
-
gr.Markdown('# ' + _TITLE)
|
92 |
-
gr.Markdown(_DESCRIPTION)
|
93 |
-
with gr.Row(variant='panel'):
|
94 |
-
with gr.Column(scale=1):
|
95 |
-
input_image = gr.Image(type='pil', image_mode='RGBA', height=320, label='Input image')
|
96 |
-
|
97 |
-
example_folder = os.path.join(os.path.dirname(__file__), "./files")
|
98 |
-
example_fns = [os.path.join(example_folder, example) for example in os.listdir(example_folder)]
|
99 |
-
gr.Examples(
|
100 |
-
examples=example_fns,
|
101 |
-
inputs=[input_image],
|
102 |
-
# outputs=[input_image],
|
103 |
-
cache_examples=False,
|
104 |
-
label='Examples (click one of the images below to start)',
|
105 |
-
examples_per_page=30
|
106 |
-
)
|
107 |
-
with gr.Column(scale=1):
|
108 |
-
|
109 |
-
with gr.Accordion('Advanced options', open=True):
|
110 |
-
with gr.Column():
|
111 |
-
|
112 |
-
domain = gr.Radio(
|
113 |
-
[
|
114 |
-
("Outdoor", "outdoor"),
|
115 |
-
("Indoor", "indoor"),
|
116 |
-
("Object", "object"),
|
117 |
-
],
|
118 |
-
label="Data Type (Must Select One matches your image)",
|
119 |
-
value="indoor",
|
120 |
-
)
|
121 |
-
guidance_scale = gr.Slider(
|
122 |
-
label="Classifier Free Guidance Scale",
|
123 |
-
minimum=1,
|
124 |
-
maximum=5,
|
125 |
-
step=1,
|
126 |
-
value=3,
|
127 |
-
)
|
128 |
-
denoising_steps = gr.Slider(
|
129 |
-
label="Number of denoising steps (More stepes, better quality)",
|
130 |
-
minimum=1,
|
131 |
-
maximum=50,
|
132 |
-
step=1,
|
133 |
-
value=20,
|
134 |
-
)
|
135 |
-
ensemble_size = gr.Slider(
|
136 |
-
label="Ensemble size (1 will be enough. More steps, higher accuracy)",
|
137 |
-
minimum=1,
|
138 |
-
maximum=15,
|
139 |
-
step=1,
|
140 |
-
value=1,
|
141 |
-
)
|
142 |
-
processing_res = gr.Radio(
|
143 |
-
[
|
144 |
-
("Native", 0),
|
145 |
-
("Recommended", 768),
|
146 |
-
],
|
147 |
-
label="Processing resolution",
|
148 |
-
value=768,
|
149 |
-
)
|
150 |
-
|
151 |
-
|
152 |
-
run_btn = gr.Button('Generate', variant='primary', interactive=True)
|
153 |
-
with gr.Row():
|
154 |
-
with gr.Column():
|
155 |
-
depth = gr.Image(interactive=False, show_label=False)
|
156 |
-
with gr.Column():
|
157 |
-
normal = gr.Image(interactive=False, show_label=False)
|
158 |
-
|
159 |
-
|
160 |
-
run_btn.click(fn=depth_normal,
|
161 |
-
inputs=[input_image, denoising_steps,
|
162 |
-
ensemble_size,
|
163 |
-
processing_res,
|
164 |
-
guidance_scale,
|
165 |
-
domain],
|
166 |
-
outputs=[depth, normal]
|
167 |
-
)
|
168 |
-
demo.queue().launch(share=True, max_threads=80)
|
169 |
-
|
170 |
-
|
171 |
-
if __name__ == '__main__':
|
172 |
-
fire.Fire(run_demo)
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|