Update preprocessing_router.py
Browse files- preprocessing_router.py +16 -1
preprocessing_router.py
CHANGED
|
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|
| 2 |
|
| 3 |
from fastapi import APIRouter, UploadFile, File, Form, BackgroundTasks, HTTPException, Body
|
| 4 |
from fastapi.responses import FileResponse
|
| 5 |
-
from pathlib import Path
|
| 6 |
from datetime import datetime
|
| 7 |
from enum import Enum
|
| 8 |
from typing import Dict, Any, List
|
|
@@ -12,6 +11,7 @@ import uuid
|
|
| 12 |
import numpy as np
|
| 13 |
import cv2
|
| 14 |
import tempfile
|
|
|
|
| 15 |
|
| 16 |
from casting_loader import ensure_chroma, build_faces_index, build_voices_index
|
| 17 |
from llm_router import load_yaml, LLMRouter
|
|
@@ -212,6 +212,16 @@ async def load_casting(
|
|
| 212 |
return {"ok": True, "faces": n_faces, "voices": n_voices}
|
| 213 |
|
| 214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
@router.post("/finalize_casting")
|
| 216 |
async def finalize_casting(
|
| 217 |
payload: dict = Body(...),
|
|
@@ -225,6 +235,11 @@ async def finalize_casting(
|
|
| 225 |
video_hash = payload.get("video_hash") or "empty"
|
| 226 |
voice_clusters = payload.get("voice_clusters", []) or []
|
| 227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
if not video_name or not base_dir:
|
| 229 |
raise HTTPException(status_code=400, detail="Missing video_name or base_dir")
|
| 230 |
|
|
|
|
| 2 |
|
| 3 |
from fastapi import APIRouter, UploadFile, File, Form, BackgroundTasks, HTTPException, Body
|
| 4 |
from fastapi.responses import FileResponse
|
|
|
|
| 5 |
from datetime import datetime
|
| 6 |
from enum import Enum
|
| 7 |
from typing import Dict, Any, List
|
|
|
|
| 11 |
import numpy as np
|
| 12 |
import cv2
|
| 13 |
import tempfile
|
| 14 |
+
from pathlib import Path
|
| 15 |
|
| 16 |
from casting_loader import ensure_chroma, build_faces_index, build_voices_index
|
| 17 |
from llm_router import load_yaml, LLMRouter
|
|
|
|
| 212 |
return {"ok": True, "faces": n_faces, "voices": n_voices}
|
| 213 |
|
| 214 |
|
| 215 |
+
from pathlib import Path
|
| 216 |
+
def find_video_hash(filename: str, media_root) -> str | None:
|
| 217 |
+
for hash_dir in media_root.iterdir():
|
| 218 |
+
if hash_dir.is_dir():
|
| 219 |
+
clips_dir = hash_dir / "clips"
|
| 220 |
+
video_path = clips_dir / filename
|
| 221 |
+
if video_path.exists():
|
| 222 |
+
return hash_dir.name
|
| 223 |
+
return None
|
| 224 |
+
|
| 225 |
@router.post("/finalize_casting")
|
| 226 |
async def finalize_casting(
|
| 227 |
payload: dict = Body(...),
|
|
|
|
| 235 |
video_hash = payload.get("video_hash") or "empty"
|
| 236 |
voice_clusters = payload.get("voice_clusters", []) or []
|
| 237 |
|
| 238 |
+
MEDIA_ROOT = _P("/data/media")
|
| 239 |
+
video_hash = find_video_hash(video_name,MEDIA_ROOT)
|
| 240 |
+
print(video_name)
|
| 241 |
+
print(characters)
|
| 242 |
+
print(voice_clusters)
|
| 243 |
if not video_name or not base_dir:
|
| 244 |
raise HTTPException(status_code=400, detail="Missing video_name or base_dir")
|
| 245 |
|