Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -11,9 +11,6 @@ from gradio_imageslider import ImageSlider
|
|
11 |
from pathlib import Path
|
12 |
from gradio.utils import get_cache_folder
|
13 |
|
14 |
-
# Constants
|
15 |
-
DEFAULT_SHARPNESS = 2
|
16 |
-
|
17 |
class Examples(gr.helpers.Examples):
|
18 |
def __init__(self, *args, directory_name=None, **kwargs):
|
19 |
super().__init__(*args, **kwargs, _initiated_directly=False)
|
@@ -24,13 +21,12 @@ class Examples(gr.helpers.Examples):
|
|
24 |
|
25 |
def load_predictor():
|
26 |
"""Load model predictor using torch.hub"""
|
27 |
-
predictor = torch.hub.load("hugoycj/StableNormal", "
|
28 |
return predictor
|
29 |
|
30 |
def process_image(
|
31 |
predictor,
|
32 |
path_input: str,
|
33 |
-
sharpness: int = DEFAULT_SHARPNESS,
|
34 |
data_type: str = "object"
|
35 |
) -> tuple:
|
36 |
"""Process single image"""
|
@@ -42,8 +38,7 @@ def process_image(
|
|
42 |
|
43 |
# Load and process image
|
44 |
input_image = Image.open(path_input)
|
45 |
-
normal_image = predictor(input_image,
|
46 |
-
match_input_resolution=False, data_type=data_type)
|
47 |
normal_image.save(out_path)
|
48 |
|
49 |
yield [input_image, out_path]
|
@@ -57,23 +52,8 @@ def create_demo():
|
|
57 |
|
58 |
# Define markdown content
|
59 |
HEADER_MD = """
|
60 |
-
# 🎪 StableNormal Turbo
|
61 |
-
|
62 |
-
### ✨ What's Cooking in Our Beta Kitchen? ✨
|
63 |
-
- **Zoom Zoom**: 2x faster - because waiting is boring!
|
64 |
-
- **Sharp as a Tack**: Better quality for those pixel-perfect folks
|
65 |
-
- **Your Way**: Tweak the sharpness slider and watch the magic happen
|
66 |
-
- **Pick Your Fighter**: Objects, Scenes, or Humans - we've got you covered!
|
67 |
-
|
68 |
-
### 🎯 Pro Tips
|
69 |
-
- Start with lower sharpness for a quick, stable result
|
70 |
-
- Want more details? Crank it up, but watch out for those floating bits!
|
71 |
-
- Sweet spot is usually around 2-3 for most images 😉
|
72 |
-
- If you get a flat result, try:
|
73 |
-
* Different sharpness
|
74 |
-
* Another image crop
|
75 |
-
* Another mode
|
76 |
-
|
77 |
<p align="center">
|
78 |
<a title="Website" href="https://stable-x.github.io/StableNormal/" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
|
79 |
<img src="https://www.obukhov.ai/img/badges/badge-website.svg">
|
@@ -111,14 +91,6 @@ def create_demo():
|
|
111 |
with gr.Row():
|
112 |
with gr.Column():
|
113 |
object_input = gr.Image(label="Input Object Image", type="filepath")
|
114 |
-
object_sharpness = gr.Slider(
|
115 |
-
minimum=1,
|
116 |
-
maximum=10,
|
117 |
-
value=DEFAULT_SHARPNESS,
|
118 |
-
step=1,
|
119 |
-
label="Sharpness (inference steps)",
|
120 |
-
info="Higher values produce sharper results but take longer"
|
121 |
-
)
|
122 |
with gr.Row():
|
123 |
object_submit_btn = gr.Button("Compute Normal", variant="primary")
|
124 |
object_reset_btn = gr.Button("Reset")
|
@@ -150,19 +122,19 @@ def create_demo():
|
|
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"),
|
153 |
-
inputs=
|
154 |
outputs=None,
|
155 |
queue=False,
|
156 |
).success(
|
157 |
fn=process_object,
|
158 |
-
inputs=
|
159 |
outputs=[object_output_slider],
|
160 |
)
|
161 |
|
162 |
object_reset_btn.click(
|
163 |
fn=lambda: (None, DEFAULT_SHARPNESS, None),
|
164 |
inputs=[],
|
165 |
-
outputs=[object_input,
|
166 |
queue=False,
|
167 |
)
|
168 |
|
|
|
11 |
from pathlib import Path
|
12 |
from gradio.utils import get_cache_folder
|
13 |
|
|
|
|
|
|
|
14 |
class Examples(gr.helpers.Examples):
|
15 |
def __init__(self, *args, directory_name=None, **kwargs):
|
16 |
super().__init__(*args, **kwargs, _initiated_directly=False)
|
|
|
21 |
|
22 |
def load_predictor():
|
23 |
"""Load model predictor using torch.hub"""
|
24 |
+
predictor = torch.hub.load("hugoycj/StableNormal", "StableNormal_turbo", trust_repo=True, yoso_version='yoso-normal-v1-8-1')
|
25 |
return predictor
|
26 |
|
27 |
def process_image(
|
28 |
predictor,
|
29 |
path_input: str,
|
|
|
30 |
data_type: str = "object"
|
31 |
) -> tuple:
|
32 |
"""Process single image"""
|
|
|
38 |
|
39 |
# Load and process image
|
40 |
input_image = Image.open(path_input)
|
41 |
+
normal_image = predictor(input_image, match_input_resolution=False, data_type=data_type)
|
|
|
42 |
normal_image.save(out_path)
|
43 |
|
44 |
yield [input_image, out_path]
|
|
|
52 |
|
53 |
# Define markdown content
|
54 |
HEADER_MD = """
|
55 |
+
# 🎪 StableNormal Turbo
|
56 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
<p align="center">
|
58 |
<a title="Website" href="https://stable-x.github.io/StableNormal/" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
|
59 |
<img src="https://www.obukhov.ai/img/badges/badge-website.svg">
|
|
|
91 |
with gr.Row():
|
92 |
with gr.Column():
|
93 |
object_input = gr.Image(label="Input Object Image", type="filepath")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
with gr.Row():
|
95 |
object_submit_btn = gr.Button("Compute Normal", variant="primary")
|
96 |
object_reset_btn = gr.Button("Reset")
|
|
|
122 |
# Event Handlers for Object Tab
|
123 |
object_submit_btn.click(
|
124 |
fn=lambda x, _: None if x else gr.Error("Please upload an image"),
|
125 |
+
inputs=object_input,
|
126 |
outputs=None,
|
127 |
queue=False,
|
128 |
).success(
|
129 |
fn=process_object,
|
130 |
+
inputs=object_input,
|
131 |
outputs=[object_output_slider],
|
132 |
)
|
133 |
|
134 |
object_reset_btn.click(
|
135 |
fn=lambda: (None, DEFAULT_SHARPNESS, None),
|
136 |
inputs=[],
|
137 |
+
outputs=[object_input, object_output_slider],
|
138 |
queue=False,
|
139 |
)
|
140 |
|