Update preprocessing_router.py
Browse files- preprocessing_router.py +0 -147
preprocessing_router.py
CHANGED
|
@@ -369,153 +369,6 @@ async def finalize_casting(
|
|
| 369 |
face_identities = sorted([p.name for p in faces_out.iterdir() if p.is_dir()]) if faces_out.exists() else []
|
| 370 |
voice_identities = sorted([p.name for p in voices_out.iterdir() if p.is_dir()]) if voices_out.exists() else []
|
| 371 |
|
| 372 |
-
print("faces_out exists:", faces_out.exists())
|
| 373 |
-
print("voice_out exists:", voices_out.exists())
|
| 374 |
-
print("Face identities found:", face_identities)
|
| 375 |
-
print("Voice identities found:", voice_identities)
|
| 376 |
-
|
| 377 |
-
if face_identities:
|
| 378 |
-
print("Face identities:", face_identities)
|
| 379 |
-
|
| 380 |
-
for identity in face_identities:
|
| 381 |
-
print("Procesando identidad:", identity)
|
| 382 |
-
id_dir = faces_out / identity
|
| 383 |
-
if not id_dir.is_dir():
|
| 384 |
-
print(f"No existe directorio para {identity}")
|
| 385 |
-
continue
|
| 386 |
-
|
| 387 |
-
img_path = None
|
| 388 |
-
for ext in (".jpg", ".jpeg", ".png", ".bmp", ".webp"):
|
| 389 |
-
candidates = list(id_dir.glob(f"*{ext}"))
|
| 390 |
-
if candidates:
|
| 391 |
-
img_path = candidates[0]
|
| 392 |
-
print(f"Imagen encontrada para {identity}: {img_path}")
|
| 393 |
-
break
|
| 394 |
-
|
| 395 |
-
if not img_path:
|
| 396 |
-
print(f"No se encontr贸 imagen para {identity}")
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
casting_json = {"face_col": [], "voice_col": []}
|
| 400 |
-
|
| 401 |
-
try:
|
| 402 |
-
cfg = load_yaml("config.yaml")
|
| 403 |
-
router_llm = LLMRouter(cfg)
|
| 404 |
-
except Exception:
|
| 405 |
-
router_llm = None # type: ignore
|
| 406 |
-
|
| 407 |
-
try:
|
| 408 |
-
if face_identities and router_llm is not None:
|
| 409 |
-
print("Face identities:", face_identities)
|
| 410 |
-
factory = router_llm.client_factories.get("salamandra-vision") # type: ignore[attr-defined]
|
| 411 |
-
print("Factory:", factory)
|
| 412 |
-
|
| 413 |
-
if factory is not None:
|
| 414 |
-
try:
|
| 415 |
-
vclient = factory()
|
| 416 |
-
print("VClient creado:", vclient)
|
| 417 |
-
gclient = getattr(vclient, "_client", None)
|
| 418 |
-
print("GClient obtenido:", gclient)
|
| 419 |
-
except Exception as e:
|
| 420 |
-
print("Error al crear vclient desde la factory:", e)
|
| 421 |
-
else:
|
| 422 |
-
gclient = None
|
| 423 |
-
print("No se encontr贸 la factory")
|
| 424 |
-
|
| 425 |
-
if gclient is not None:
|
| 426 |
-
for identity in face_identities:
|
| 427 |
-
print("Procesando identidad:", identity)
|
| 428 |
-
id_dir = faces_out / identity
|
| 429 |
-
if not id_dir.is_dir():
|
| 430 |
-
print(f"No existe directorio para {identity}")
|
| 431 |
-
continue
|
| 432 |
-
|
| 433 |
-
img_path = None
|
| 434 |
-
for ext in (".jpg", ".jpeg", ".png", ".bmp", ".webp"):
|
| 435 |
-
candidates = list(id_dir.glob(f"*{ext}"))
|
| 436 |
-
if candidates:
|
| 437 |
-
img_path = candidates[0]
|
| 438 |
-
print("Imagen encontrada:", img_path)
|
| 439 |
-
break
|
| 440 |
-
|
| 441 |
-
if not img_path:
|
| 442 |
-
print(f"No se encontr贸 imagen para {identity}")
|
| 443 |
-
continue
|
| 444 |
-
|
| 445 |
-
try:
|
| 446 |
-
out = gclient.predict(str(img_path), api_name="/face_image_embedding")
|
| 447 |
-
print("Salida de predict:", out)
|
| 448 |
-
|
| 449 |
-
emb = None
|
| 450 |
-
if isinstance(out, list):
|
| 451 |
-
if out and isinstance(out[0], (list, tuple, float, int)):
|
| 452 |
-
if out and isinstance(out[0], (list, tuple)):
|
| 453 |
-
emb = list(out[0])
|
| 454 |
-
else:
|
| 455 |
-
emb = list(out)
|
| 456 |
-
elif isinstance(out, dict) and "embedding" in out:
|
| 457 |
-
emb = out.get("embedding")
|
| 458 |
-
|
| 459 |
-
if not emb:
|
| 460 |
-
print(f"No se pudo extraer embedding de {identity}")
|
| 461 |
-
continue
|
| 462 |
-
|
| 463 |
-
print(f"Embedding obtenido para {identity}: {emb[:5]}...") # solo los primeros 5 valores
|
| 464 |
-
casting_json["face_col"].append({
|
| 465 |
-
"nombre": identity,
|
| 466 |
-
"embedding": emb,
|
| 467 |
-
})
|
| 468 |
-
|
| 469 |
-
except Exception as e:
|
| 470 |
-
print(f"Error al predecir {identity}: {e}")
|
| 471 |
-
|
| 472 |
-
except Exception:
|
| 473 |
-
casting_json["face_col"] = []
|
| 474 |
-
|
| 475 |
-
try:
|
| 476 |
-
if voice_identities and router_llm is not None:
|
| 477 |
-
factory = router_llm.client_factories.get("whisper-catalan") # type: ignore[attr-defined]
|
| 478 |
-
if factory is not None:
|
| 479 |
-
aclient = factory()
|
| 480 |
-
gclient = getattr(aclient, "_client", None)
|
| 481 |
-
else:
|
| 482 |
-
gclient = None
|
| 483 |
-
|
| 484 |
-
if gclient is not None:
|
| 485 |
-
for identity in voice_identities:
|
| 486 |
-
id_dir = voices_out / identity
|
| 487 |
-
if not id_dir.is_dir():
|
| 488 |
-
continue
|
| 489 |
-
wav_files = sorted([
|
| 490 |
-
p for p in id_dir.iterdir()
|
| 491 |
-
if p.is_file() and p.suffix.lower() in [".wav", ".flac", ".mp3"]
|
| 492 |
-
])
|
| 493 |
-
if not wav_files:
|
| 494 |
-
continue
|
| 495 |
-
|
| 496 |
-
wf = wav_files[0]
|
| 497 |
-
try:
|
| 498 |
-
out = gclient.predict(str(wf), api_name="/voice_embedding")
|
| 499 |
-
emb = None
|
| 500 |
-
if isinstance(out, list):
|
| 501 |
-
emb = list(out)
|
| 502 |
-
elif isinstance(out, dict) and "embedding" in out:
|
| 503 |
-
emb = out.get("embedding")
|
| 504 |
-
|
| 505 |
-
if not emb:
|
| 506 |
-
continue
|
| 507 |
-
|
| 508 |
-
casting_json["voice_col"].append({
|
| 509 |
-
"nombre": identity,
|
| 510 |
-
"embedding": emb,
|
| 511 |
-
})
|
| 512 |
-
except Exception:
|
| 513 |
-
continue
|
| 514 |
-
except Exception:
|
| 515 |
-
casting_json["voice_col"] = []
|
| 516 |
-
|
| 517 |
-
print(casting_json)
|
| 518 |
-
|
| 519 |
return {
|
| 520 |
"ok": True,
|
| 521 |
"video_name": video_name,
|
|
|
|
| 369 |
face_identities = sorted([p.name for p in faces_out.iterdir() if p.is_dir()]) if faces_out.exists() else []
|
| 370 |
voice_identities = sorted([p.name for p in voices_out.iterdir() if p.is_dir()]) if voices_out.exists() else []
|
| 371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
return {
|
| 373 |
"ok": True,
|
| 374 |
"video_name": video_name,
|