Spaces:
Running on Zero
Running on Zero
Rawal Khirodkar commited on
Commit ·
a1b264d
1
Parent(s): 5d35b38
Normal: add full-res normal image inside the accordion
Browse files
app.py
CHANGED
|
@@ -150,7 +150,7 @@ def _normal_to_rgb(normal_hwc: np.ndarray) -> np.ndarray:
|
|
| 150 |
@spaces.GPU(duration=120)
|
| 151 |
def predict(image: Image.Image, size: str, bg_mode: str):
|
| 152 |
if image is None:
|
| 153 |
-
return None, None
|
| 154 |
|
| 155 |
image_pil = image.convert("RGB")
|
| 156 |
image_rgb = np.array(image_pil)
|
|
@@ -166,11 +166,12 @@ def predict(image: Image.Image, size: str, bg_mode: str):
|
|
| 166 |
raw[~mask] = np.nan
|
| 167 |
normal[~mask] = -1.0 # → RGB(0,0,0) after vis
|
| 168 |
rgb = _normal_to_rgb(normal)
|
|
|
|
| 169 |
|
| 170 |
npy_path = tempfile.NamedTemporaryFile(delete=False, suffix=".npy").name
|
| 171 |
np.save(npy_path, raw.astype(np.float32))
|
| 172 |
|
| 173 |
-
return
|
| 174 |
|
| 175 |
|
| 176 |
# -----------------------------------------------------------------------------
|
|
@@ -258,9 +259,10 @@ with gr.Blocks(title="Sapiens2 Normal", theme=gr.themes.Soft(), css=CUSTOM_CSS)
|
|
| 258 |
gr.Examples(examples=EXAMPLES, inputs=inp, examples_per_page=14)
|
| 259 |
|
| 260 |
with gr.Accordion("Original Res + Raw Normals", open=False):
|
|
|
|
| 261 |
out_npy = gr.File(label="Raw normals (.npy float32 [-1, 1]; NaN where bg removed)")
|
| 262 |
|
| 263 |
-
run.click(predict, inputs=[inp, size, bg], outputs=[out_img, out_npy])
|
| 264 |
|
| 265 |
|
| 266 |
if __name__ == "__main__":
|
|
|
|
| 150 |
@spaces.GPU(duration=120)
|
| 151 |
def predict(image: Image.Image, size: str, bg_mode: str):
|
| 152 |
if image is None:
|
| 153 |
+
return None, None, None
|
| 154 |
|
| 155 |
image_pil = image.convert("RGB")
|
| 156 |
image_rgb = np.array(image_pil)
|
|
|
|
| 166 |
raw[~mask] = np.nan
|
| 167 |
normal[~mask] = -1.0 # → RGB(0,0,0) after vis
|
| 168 |
rgb = _normal_to_rgb(normal)
|
| 169 |
+
rgb_pil = Image.fromarray(rgb)
|
| 170 |
|
| 171 |
npy_path = tempfile.NamedTemporaryFile(delete=False, suffix=".npy").name
|
| 172 |
np.save(npy_path, raw.astype(np.float32))
|
| 173 |
|
| 174 |
+
return rgb_pil, rgb_pil, npy_path
|
| 175 |
|
| 176 |
|
| 177 |
# -----------------------------------------------------------------------------
|
|
|
|
| 259 |
gr.Examples(examples=EXAMPLES, inputs=inp, examples_per_page=14)
|
| 260 |
|
| 261 |
with gr.Accordion("Original Res + Raw Normals", open=False):
|
| 262 |
+
out_img_full = gr.Image(label="Normal (original resolution)", type="pil")
|
| 263 |
out_npy = gr.File(label="Raw normals (.npy float32 [-1, 1]; NaN where bg removed)")
|
| 264 |
|
| 265 |
+
run.click(predict, inputs=[inp, size, bg], outputs=[out_img, out_img_full, out_npy])
|
| 266 |
|
| 267 |
|
| 268 |
if __name__ == "__main__":
|