Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ from PIL import Image
|
|
| 15 |
import cv2
|
| 16 |
import timeout_decorator
|
| 17 |
import spaces
|
|
|
|
| 18 |
|
| 19 |
from registry import get_model
|
| 20 |
from core.describe_scene import describe_scene
|
|
@@ -140,17 +141,25 @@ def handle(mode, media_upload, url, run_det, det_model, det_confidence, run_seg,
|
|
| 140 |
def show_preview_from_upload(files):
|
| 141 |
if not files:
|
| 142 |
return gr.update(visible=False), gr.update(visible=False)
|
|
|
|
| 143 |
file = files[0]
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
| 146 |
img = Image.open(file).convert("RGB")
|
| 147 |
return gr.update(value=img, visible=True), gr.update(visible=False)
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
| 152 |
f.write(file.read())
|
| 153 |
-
|
|
|
|
|
|
|
| 154 |
|
| 155 |
return gr.update(visible=False), gr.update(visible=False)
|
| 156 |
|
|
|
|
| 15 |
import cv2
|
| 16 |
import timeout_decorator
|
| 17 |
import spaces
|
| 18 |
+
import tempfile
|
| 19 |
|
| 20 |
from registry import get_model
|
| 21 |
from core.describe_scene import describe_scene
|
|
|
|
| 141 |
def show_preview_from_upload(files):
|
| 142 |
if not files:
|
| 143 |
return gr.update(visible=False), gr.update(visible=False)
|
| 144 |
+
|
| 145 |
file = files[0]
|
| 146 |
+
filename = file.name.lower()
|
| 147 |
+
|
| 148 |
+
# Handle image
|
| 149 |
+
if filename.endswith((".png", ".jpg", ".jpeg", ".webp")):
|
| 150 |
img = Image.open(file).convert("RGB")
|
| 151 |
return gr.update(value=img, visible=True), gr.update(visible=False)
|
| 152 |
+
|
| 153 |
+
# Handle video
|
| 154 |
+
elif filename.endswith((".mp4", ".mov", ".avi")):
|
| 155 |
+
tmp_dir = tempfile.mkdtemp()
|
| 156 |
+
ext = os.path.splitext(filename)[-1]
|
| 157 |
+
save_path = os.path.join(tmp_dir, f"preview_video{ext}")
|
| 158 |
+
with open(save_path, "wb") as f:
|
| 159 |
f.write(file.read())
|
| 160 |
+
|
| 161 |
+
# ✅ Gradio needs a proper path for video preview
|
| 162 |
+
return gr.update(visible=False), gr.update(value=save_path, visible=True)
|
| 163 |
|
| 164 |
return gr.update(visible=False), gr.update(visible=False)
|
| 165 |
|