Update ui/callbacks.py
Browse files- ui/callbacks.py +34 -8
ui/callbacks.py
CHANGED
|
@@ -4,16 +4,17 @@
|
|
| 4 |
---------------------------------
|
| 5 |
All functions here are *thin* wrappers wired to the Gradio interface.
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
• Passes that value straight through to `process_video_fixed(...)`
|
| 12 |
"""
|
| 13 |
|
| 14 |
from __future__ import annotations
|
| 15 |
-
import os
|
| 16 |
from typing import Any, Dict, Tuple
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# ---- Core pipeline wrappers (from core/app.py) ----
|
| 19 |
from core.app import (
|
|
@@ -211,10 +212,35 @@ def cb_use_gen_bg(path_text: str):
|
|
| 211 |
|
| 212 |
|
| 213 |
# ------------------------------------------------------------------
|
| 214 |
-
# PREVIEWS
|
| 215 |
# ------------------------------------------------------------------
|
| 216 |
def cb_video_changed(vid_path: str):
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
|
| 219 |
def cb_custom_bg_preview(file_obj: dict | None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
return None
|
|
|
|
| 4 |
---------------------------------
|
| 5 |
All functions here are *thin* wrappers wired to the Gradio interface.
|
| 6 |
|
| 7 |
+
• key_color_mode parameter already added (matches ui_components.py)
|
| 8 |
+
• PREVIEW FUNCTIONS NOW IMPLEMENTED:
|
| 9 |
+
- cb_video_changed → returns first frame
|
| 10 |
+
- cb_custom_bg_preview → returns uploaded image
|
|
|
|
| 11 |
"""
|
| 12 |
|
| 13 |
from __future__ import annotations
|
| 14 |
+
import os, cv2 # ← cv2 was already needed by fallback gen
|
| 15 |
from typing import Any, Dict, Tuple
|
| 16 |
+
import numpy as np
|
| 17 |
+
from PIL import Image
|
| 18 |
|
| 19 |
# ---- Core pipeline wrappers (from core/app.py) ----
|
| 20 |
from core.app import (
|
|
|
|
| 212 |
|
| 213 |
|
| 214 |
# ------------------------------------------------------------------
|
| 215 |
+
# PREVIEWS
|
| 216 |
# ------------------------------------------------------------------
|
| 217 |
def cb_video_changed(vid_path: str):
|
| 218 |
+
"""
|
| 219 |
+
Extract first frame of the uploaded video for a quick preview.
|
| 220 |
+
Returns a numpy RGB array (Gradio will display it).
|
| 221 |
+
"""
|
| 222 |
+
try:
|
| 223 |
+
if not vid_path:
|
| 224 |
+
return None
|
| 225 |
+
cap = cv2.VideoCapture(vid_path)
|
| 226 |
+
ok, frame = cap.read()
|
| 227 |
+
cap.release()
|
| 228 |
+
if not ok:
|
| 229 |
+
return None
|
| 230 |
+
# Convert BGR→RGB for correct colours in the browser
|
| 231 |
+
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 232 |
+
return frame_rgb
|
| 233 |
+
except Exception:
|
| 234 |
+
return None
|
| 235 |
|
| 236 |
def cb_custom_bg_preview(file_obj: dict | None):
|
| 237 |
+
"""
|
| 238 |
+
Display the uploaded background image (if any) as a preview.
|
| 239 |
+
"""
|
| 240 |
+
try:
|
| 241 |
+
if file_obj and file_obj.get("name"):
|
| 242 |
+
img = Image.open(file_obj["name"]).convert("RGB")
|
| 243 |
+
return np.array(img)
|
| 244 |
+
except Exception:
|
| 245 |
+
pass
|
| 246 |
return None
|