Write outputs beside the uploaded input so Gradio serves them (fixes 404 on depth URL)
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
-
import tempfile
|
| 4 |
from functools import partial
|
| 5 |
from pathlib import Path
|
| 6 |
|
|
@@ -102,7 +101,8 @@ def _infer_video(path: str) -> str:
|
|
| 102 |
net, transform = _device_and_model()
|
| 103 |
predictions = net.infer_video(transform(f) for f in frames())
|
| 104 |
|
| 105 |
-
|
|
|
|
| 106 |
writer = None
|
| 107 |
written = 0
|
| 108 |
with av.open(out_path, mode="w") as out:
|
|
@@ -138,7 +138,9 @@ def predict_depth(image: FileData) -> FileData:
|
|
| 138 |
"""Estimate metric depth for an uploaded photo; returns the colorized depth map."""
|
| 139 |
img, f_px = load_rgb(image["path"]) # f_px: the focal length recorded in the photo, or None
|
| 140 |
rgb = _infer_image(img, f_px)
|
| 141 |
-
|
|
|
|
|
|
|
| 142 |
Image.fromarray(rgb).save(out_path)
|
| 143 |
return FileData(path=str(out_path))
|
| 144 |
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
|
|
|
| 3 |
from functools import partial
|
| 4 |
from pathlib import Path
|
| 5 |
|
|
|
|
| 101 |
net, transform = _device_and_model()
|
| 102 |
predictions = net.infer_video(transform(f) for f in frames())
|
| 103 |
|
| 104 |
+
# Beside the uploaded input, which is in Gradio's servable upload cache.
|
| 105 |
+
out_path = Path(path).with_suffix(".depth.mp4")
|
| 106 |
writer = None
|
| 107 |
written = 0
|
| 108 |
with av.open(out_path, mode="w") as out:
|
|
|
|
| 138 |
"""Estimate metric depth for an uploaded photo; returns the colorized depth map."""
|
| 139 |
img, f_px = load_rgb(image["path"]) # f_px: the focal length recorded in the photo, or None
|
| 140 |
rgb = _infer_image(img, f_px)
|
| 141 |
+
# Write beside the uploaded input: it is in Gradio's upload cache, which is servable; a raw
|
| 142 |
+
# tempfile.gettempdir() path is not, and its URL 404s in the browser.
|
| 143 |
+
out_path = Path(image["path"]).with_suffix(".depth.png")
|
| 144 |
Image.fromarray(rgb).save(out_path)
|
| 145 |
return FileData(path=str(out_path))
|
| 146 |
|