Spaces:
Running
Running
feat: mount /tmp directory and add client-side fallback logic for image previews
Browse files- app.py +2 -1
- index.html +14 -1
app.py
CHANGED
|
@@ -342,8 +342,9 @@ def extract_glb_api(state_path: str, decimation_target: int, texture_size: int)
|
|
| 342 |
glb.export(out_glb, extension_webp=True)
|
| 343 |
return FileData(path=out_glb)
|
| 344 |
|
| 345 |
-
# Mount assets and tmp for direct access
|
| 346 |
app.mount("/assets", StaticFiles(directory="assets"), name="assets")
|
|
|
|
| 347 |
|
| 348 |
if __name__ == "__main__":
|
| 349 |
# Re-install utils3d as in original app.py
|
|
|
|
| 342 |
glb.export(out_glb, extension_webp=True)
|
| 343 |
return FileData(path=out_glb)
|
| 344 |
|
| 345 |
+
# Mount assets and tmp for direct access
|
| 346 |
app.mount("/assets", StaticFiles(directory="assets"), name="assets")
|
| 347 |
+
app.mount("/tmp", StaticFiles(directory=TMP_DIR), name="tmp")
|
| 348 |
|
| 349 |
if __name__ == "__main__":
|
| 350 |
# Re-install utils3d as in original app.py
|
index.html
CHANGED
|
@@ -810,9 +810,22 @@
|
|
| 810 |
Object.entries(renderPaths).forEach(([mode, files]) => {
|
| 811 |
files.forEach((file, i) => {
|
| 812 |
const img = document.createElement('img');
|
| 813 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 814 |
img.className = 'preview-frame';
|
| 815 |
img.id = `frame-${mode}-${i}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 816 |
container.appendChild(img);
|
| 817 |
});
|
| 818 |
});
|
|
|
|
| 810 |
Object.entries(renderPaths).forEach(([mode, files]) => {
|
| 811 |
files.forEach((file, i) => {
|
| 812 |
const img = document.createElement('img');
|
| 813 |
+
// Try the URL from Gradio, fallback to our mounted /tmp route if it's an absolute local path
|
| 814 |
+
let url = file.url;
|
| 815 |
+
if (!url && file.path) {
|
| 816 |
+
const filename = file.path.split(/[\\/]/).pop();
|
| 817 |
+
url = `/tmp/${filename}`;
|
| 818 |
+
}
|
| 819 |
+
img.src = url;
|
| 820 |
img.className = 'preview-frame';
|
| 821 |
img.id = `frame-${mode}-${i}`;
|
| 822 |
+
img.onerror = () => {
|
| 823 |
+
// Fallback attempt if the first URL fails
|
| 824 |
+
const filename = file.path ? file.path.split(/[\\/]/).pop() : null;
|
| 825 |
+
if (filename && !img.src.includes('/tmp/')) {
|
| 826 |
+
img.src = `/tmp/${filename}`;
|
| 827 |
+
}
|
| 828 |
+
};
|
| 829 |
container.appendChild(img);
|
| 830 |
});
|
| 831 |
});
|