Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,7 +24,7 @@ class Examples(gr.helpers.Examples):
|
|
| 24 |
|
| 25 |
def load_predictor():
|
| 26 |
"""Load model predictor using torch.hub"""
|
| 27 |
-
predictor = torch.hub.load("hugoycj/StableNormal", "StableNormal", trust_repo=True)
|
| 28 |
return predictor
|
| 29 |
|
| 30 |
def process_image(
|
|
@@ -54,8 +54,6 @@ def create_demo():
|
|
| 54 |
|
| 55 |
# Create processing functions for each data type
|
| 56 |
process_object = spaces.GPU(functools.partial(process_image, predictor, data_type="object"))
|
| 57 |
-
process_scene = spaces.GPU(functools.partial(process_image, predictor, data_type="indoor"))
|
| 58 |
-
process_human = spaces.GPU(functools.partial(process_image, predictor, data_type="object"))
|
| 59 |
|
| 60 |
# Define markdown content
|
| 61 |
HEADER_MD = """
|
|
@@ -149,88 +147,6 @@ def create_demo():
|
|
| 149 |
examples_per_page=50,
|
| 150 |
)
|
| 151 |
|
| 152 |
-
# Scene Tab
|
| 153 |
-
with gr.Tab("Scene"):
|
| 154 |
-
with gr.Row():
|
| 155 |
-
with gr.Column():
|
| 156 |
-
scene_input = gr.Image(label="Input Scene Image", type="filepath")
|
| 157 |
-
scene_sharpness = gr.Slider(
|
| 158 |
-
minimum=1,
|
| 159 |
-
maximum=10,
|
| 160 |
-
value=DEFAULT_SHARPNESS,
|
| 161 |
-
step=1,
|
| 162 |
-
label="Sharpness (inference steps)",
|
| 163 |
-
info="Higher values produce sharper results but take longer"
|
| 164 |
-
)
|
| 165 |
-
with gr.Row():
|
| 166 |
-
scene_submit_btn = gr.Button("Compute Normal", variant="primary")
|
| 167 |
-
scene_reset_btn = gr.Button("Reset")
|
| 168 |
-
with gr.Column():
|
| 169 |
-
scene_output_slider = ImageSlider(
|
| 170 |
-
label="Normal outputs",
|
| 171 |
-
type="filepath",
|
| 172 |
-
show_download_button=True,
|
| 173 |
-
show_share_button=True,
|
| 174 |
-
interactive=False,
|
| 175 |
-
elem_classes="slider",
|
| 176 |
-
position=0.25,
|
| 177 |
-
)
|
| 178 |
-
|
| 179 |
-
Examples(
|
| 180 |
-
fn=process_scene,
|
| 181 |
-
examples=sorted([
|
| 182 |
-
os.path.join("files", "scene", name)
|
| 183 |
-
for name in os.listdir(os.path.join("files", "scene"))
|
| 184 |
-
if os.path.exists(os.path.join("files", "scene"))
|
| 185 |
-
]),
|
| 186 |
-
inputs=[scene_input],
|
| 187 |
-
outputs=[scene_output_slider],
|
| 188 |
-
cache_examples=True,
|
| 189 |
-
directory_name="examples_scene",
|
| 190 |
-
examples_per_page=50,
|
| 191 |
-
)
|
| 192 |
-
|
| 193 |
-
# Human Tab
|
| 194 |
-
with gr.Tab("Human"):
|
| 195 |
-
with gr.Row():
|
| 196 |
-
with gr.Column():
|
| 197 |
-
human_input = gr.Image(label="Input Human Image", type="filepath")
|
| 198 |
-
human_sharpness = gr.Slider(
|
| 199 |
-
minimum=1,
|
| 200 |
-
maximum=10,
|
| 201 |
-
value=DEFAULT_SHARPNESS,
|
| 202 |
-
step=1,
|
| 203 |
-
label="Sharpness (inference steps)",
|
| 204 |
-
info="Higher values produce sharper results but take longer"
|
| 205 |
-
)
|
| 206 |
-
with gr.Row():
|
| 207 |
-
human_submit_btn = gr.Button("Compute Normal", variant="primary")
|
| 208 |
-
human_reset_btn = gr.Button("Reset")
|
| 209 |
-
with gr.Column():
|
| 210 |
-
human_output_slider = ImageSlider(
|
| 211 |
-
label="Normal outputs",
|
| 212 |
-
type="filepath",
|
| 213 |
-
show_download_button=True,
|
| 214 |
-
show_share_button=True,
|
| 215 |
-
interactive=False,
|
| 216 |
-
elem_classes="slider",
|
| 217 |
-
position=0.25,
|
| 218 |
-
)
|
| 219 |
-
|
| 220 |
-
Examples(
|
| 221 |
-
fn=process_human,
|
| 222 |
-
examples=sorted([
|
| 223 |
-
os.path.join("files", "human", name)
|
| 224 |
-
for name in os.listdir(os.path.join("files", "human"))
|
| 225 |
-
if os.path.exists(os.path.join("files", "human"))
|
| 226 |
-
]),
|
| 227 |
-
inputs=[human_input],
|
| 228 |
-
outputs=[human_output_slider],
|
| 229 |
-
cache_examples=True,
|
| 230 |
-
directory_name="examples_human",
|
| 231 |
-
examples_per_page=50,
|
| 232 |
-
)
|
| 233 |
-
|
| 234 |
# Event Handlers for Object Tab
|
| 235 |
object_submit_btn.click(
|
| 236 |
fn=lambda x, _: None if x else gr.Error("Please upload an image"),
|
|
@@ -250,44 +166,6 @@ def create_demo():
|
|
| 250 |
queue=False,
|
| 251 |
)
|
| 252 |
|
| 253 |
-
# Event Handlers for Scene Tab
|
| 254 |
-
scene_submit_btn.click(
|
| 255 |
-
fn=lambda x, _: None if x else gr.Error("Please upload an image"),
|
| 256 |
-
inputs=[scene_input, scene_sharpness],
|
| 257 |
-
outputs=None,
|
| 258 |
-
queue=False,
|
| 259 |
-
).success(
|
| 260 |
-
fn=process_scene,
|
| 261 |
-
inputs=[scene_input, scene_sharpness],
|
| 262 |
-
outputs=[scene_output_slider],
|
| 263 |
-
)
|
| 264 |
-
|
| 265 |
-
scene_reset_btn.click(
|
| 266 |
-
fn=lambda: (None, DEFAULT_SHARPNESS, None),
|
| 267 |
-
inputs=[],
|
| 268 |
-
outputs=[scene_input, scene_sharpness, scene_output_slider],
|
| 269 |
-
queue=False,
|
| 270 |
-
)
|
| 271 |
-
|
| 272 |
-
# Event Handlers for Human Tab
|
| 273 |
-
human_submit_btn.click(
|
| 274 |
-
fn=lambda x, _: None if x else gr.Error("Please upload an image"),
|
| 275 |
-
inputs=[human_input, human_sharpness],
|
| 276 |
-
outputs=None,
|
| 277 |
-
queue=False,
|
| 278 |
-
).success(
|
| 279 |
-
fn=process_human,
|
| 280 |
-
inputs=[human_input, human_sharpness],
|
| 281 |
-
outputs=[human_output_slider],
|
| 282 |
-
)
|
| 283 |
-
|
| 284 |
-
human_reset_btn.click(
|
| 285 |
-
fn=lambda: (None, DEFAULT_SHARPNESS, None),
|
| 286 |
-
inputs=[],
|
| 287 |
-
outputs=[human_input, human_sharpness, human_output_slider],
|
| 288 |
-
queue=False,
|
| 289 |
-
)
|
| 290 |
-
|
| 291 |
return demo
|
| 292 |
|
| 293 |
def main():
|
|
|
|
| 24 |
|
| 25 |
def load_predictor():
|
| 26 |
"""Load model predictor using torch.hub"""
|
| 27 |
+
predictor = torch.hub.load("hugoycj/StableNormal", "StableNormal", trust_repo=True, yoso_version='yoso-normal-v1-7')
|
| 28 |
return predictor
|
| 29 |
|
| 30 |
def process_image(
|
|
|
|
| 54 |
|
| 55 |
# Create processing functions for each data type
|
| 56 |
process_object = spaces.GPU(functools.partial(process_image, predictor, data_type="object"))
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# Define markdown content
|
| 59 |
HEADER_MD = """
|
|
|
|
| 147 |
examples_per_page=50,
|
| 148 |
)
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
# Event Handlers for Object Tab
|
| 151 |
object_submit_btn.click(
|
| 152 |
fn=lambda x, _: None if x else gr.Error("Please upload an image"),
|
|
|
|
| 166 |
queue=False,
|
| 167 |
)
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
return demo
|
| 170 |
|
| 171 |
def main():
|