predict_depth returns inline data URI; request ground truth logged
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
|
|
|
| 3 |
from functools import partial
|
| 4 |
from pathlib import Path
|
| 5 |
|
|
@@ -169,8 +170,8 @@ app = Server(
|
|
| 169 |
|
| 170 |
|
| 171 |
@app.api(name="predict_depth")
|
| 172 |
-
def predict_depth(image: FileData, request: gr.Request) ->
|
| 173 |
-
"""Estimate metric depth for an uploaded photo; returns
|
| 174 |
# request is taken explicitly: Server-mode ZeroGPU token forwarding is more reliable with it
|
| 175 |
# in the signature (see MiniMaxAI/MiniMax-H3-Turbo-Lora commit 7db57ff).
|
| 176 |
try:
|
|
@@ -179,12 +180,14 @@ def predict_depth(image: FileData, request: gr.Request) -> FileData:
|
|
| 179 |
raise gr.Error(
|
| 180 |
f"That upload could not be read as an image ({type(err).__name__}) \u2014 try a JPG or PNG."
|
| 181 |
) from err
|
|
|
|
| 182 |
rgb = _infer_image(img, f_px)
|
| 183 |
-
#
|
| 184 |
-
#
|
| 185 |
out_path = Path(image["path"]).with_suffix(".depth.png")
|
| 186 |
Image.fromarray(rgb).save(out_path)
|
| 187 |
-
|
|
|
|
| 188 |
|
| 189 |
|
| 190 |
@app.api(name="predict_depth_video")
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
+
import base64
|
| 4 |
from functools import partial
|
| 5 |
from pathlib import Path
|
| 6 |
|
|
|
|
| 170 |
|
| 171 |
|
| 172 |
@app.api(name="predict_depth")
|
| 173 |
+
def predict_depth(image: FileData, request: gr.Request) -> str:
|
| 174 |
+
"""Estimate metric depth for an uploaded photo; returns it inline as a data URI."""
|
| 175 |
# request is taken explicitly: Server-mode ZeroGPU token forwarding is more reliable with it
|
| 176 |
# in the signature (see MiniMaxAI/MiniMax-H3-Turbo-Lora commit 7db57ff).
|
| 177 |
try:
|
|
|
|
| 180 |
raise gr.Error(
|
| 181 |
f"That upload could not be read as an image ({type(err).__name__}) \u2014 try a JPG or PNG."
|
| 182 |
) from err
|
| 183 |
+
print(f"predict_depth: {img.shape[1]}x{img.shape[0]} px, f_px={f_px}", flush=True)
|
| 184 |
rgb = _infer_image(img, f_px)
|
| 185 |
+
# Inline as a data URI (the P-Image-OSS pattern): no /gradio_api/file hop for the browser to
|
| 186 |
+
# fail on, and the request cannot 'succeed' while silently serving nothing.
|
| 187 |
out_path = Path(image["path"]).with_suffix(".depth.png")
|
| 188 |
Image.fromarray(rgb).save(out_path)
|
| 189 |
+
print(f"predict_depth: wrote {out_path.stat().st_size} bytes", flush=True)
|
| 190 |
+
return "data:image/png;base64," + base64.b64encode(out_path.read_bytes()).decode()
|
| 191 |
|
| 192 |
|
| 193 |
@app.api(name="predict_depth_video")
|