Update preprocessing_router.py
Browse files- preprocessing_router.py +24 -6
preprocessing_router.py
CHANGED
|
@@ -314,29 +314,43 @@ async def finalize_casting(
|
|
| 314 |
|
| 315 |
try:
|
| 316 |
if face_identities and router_llm is not None:
|
|
|
|
| 317 |
factory = router_llm.client_factories.get("salamandra-vision") # type: ignore[attr-defined]
|
|
|
|
|
|
|
| 318 |
if factory is not None:
|
| 319 |
vclient = factory()
|
|
|
|
| 320 |
gclient = getattr(vclient, "_client", None)
|
|
|
|
| 321 |
else:
|
| 322 |
gclient = None
|
| 323 |
-
|
|
|
|
| 324 |
if gclient is not None:
|
| 325 |
for identity in face_identities:
|
|
|
|
| 326 |
id_dir = faces_out / identity
|
| 327 |
if not id_dir.is_dir():
|
|
|
|
| 328 |
continue
|
|
|
|
| 329 |
img_path = None
|
| 330 |
for ext in (".jpg", ".jpeg", ".png", ".bmp", ".webp"):
|
| 331 |
candidates = list(id_dir.glob(f"*{ext}"))
|
| 332 |
if candidates:
|
| 333 |
img_path = candidates[0]
|
|
|
|
| 334 |
break
|
|
|
|
| 335 |
if not img_path:
|
|
|
|
| 336 |
continue
|
| 337 |
-
|
| 338 |
try:
|
| 339 |
out = gclient.predict(str(img_path), api_name="/face_image_embedding")
|
|
|
|
|
|
|
| 340 |
emb = None
|
| 341 |
if isinstance(out, list):
|
| 342 |
if out and isinstance(out[0], (list, tuple, float, int)):
|
|
@@ -346,16 +360,20 @@ async def finalize_casting(
|
|
| 346 |
emb = list(out)
|
| 347 |
elif isinstance(out, dict) and "embedding" in out:
|
| 348 |
emb = out.get("embedding")
|
| 349 |
-
|
| 350 |
if not emb:
|
|
|
|
| 351 |
continue
|
| 352 |
-
|
|
|
|
| 353 |
casting_json["face_col"].append({
|
| 354 |
"nombre": identity,
|
| 355 |
"embedding": emb,
|
| 356 |
})
|
| 357 |
-
|
| 358 |
-
|
|
|
|
|
|
|
| 359 |
except Exception:
|
| 360 |
casting_json["face_col"] = []
|
| 361 |
|
|
|
|
| 314 |
|
| 315 |
try:
|
| 316 |
if face_identities and router_llm is not None:
|
| 317 |
+
print("Face identities:", face_identities)
|
| 318 |
factory = router_llm.client_factories.get("salamandra-vision") # type: ignore[attr-defined]
|
| 319 |
+
print("Factory:", factory)
|
| 320 |
+
|
| 321 |
if factory is not None:
|
| 322 |
vclient = factory()
|
| 323 |
+
print("VClient creado:", vclient)
|
| 324 |
gclient = getattr(vclient, "_client", None)
|
| 325 |
+
print("GClient obtenido:", gclient)
|
| 326 |
else:
|
| 327 |
gclient = None
|
| 328 |
+
print("No se encontr贸 la factory")
|
| 329 |
+
|
| 330 |
if gclient is not None:
|
| 331 |
for identity in face_identities:
|
| 332 |
+
print("Procesando identidad:", identity)
|
| 333 |
id_dir = faces_out / identity
|
| 334 |
if not id_dir.is_dir():
|
| 335 |
+
print(f"No existe directorio para {identity}")
|
| 336 |
continue
|
| 337 |
+
|
| 338 |
img_path = None
|
| 339 |
for ext in (".jpg", ".jpeg", ".png", ".bmp", ".webp"):
|
| 340 |
candidates = list(id_dir.glob(f"*{ext}"))
|
| 341 |
if candidates:
|
| 342 |
img_path = candidates[0]
|
| 343 |
+
print("Imagen encontrada:", img_path)
|
| 344 |
break
|
| 345 |
+
|
| 346 |
if not img_path:
|
| 347 |
+
print(f"No se encontr贸 imagen para {identity}")
|
| 348 |
continue
|
| 349 |
+
|
| 350 |
try:
|
| 351 |
out = gclient.predict(str(img_path), api_name="/face_image_embedding")
|
| 352 |
+
print("Salida de predict:", out)
|
| 353 |
+
|
| 354 |
emb = None
|
| 355 |
if isinstance(out, list):
|
| 356 |
if out and isinstance(out[0], (list, tuple, float, int)):
|
|
|
|
| 360 |
emb = list(out)
|
| 361 |
elif isinstance(out, dict) and "embedding" in out:
|
| 362 |
emb = out.get("embedding")
|
| 363 |
+
|
| 364 |
if not emb:
|
| 365 |
+
print(f"No se pudo extraer embedding de {identity}")
|
| 366 |
continue
|
| 367 |
+
|
| 368 |
+
print(f"Embedding obtenido para {identity}: {emb[:5]}...") # solo los primeros 5 valores
|
| 369 |
casting_json["face_col"].append({
|
| 370 |
"nombre": identity,
|
| 371 |
"embedding": emb,
|
| 372 |
})
|
| 373 |
+
|
| 374 |
+
except Exception as e:
|
| 375 |
+
print(f"Error al predecir {identity}: {e}")
|
| 376 |
+
|
| 377 |
except Exception:
|
| 378 |
casting_json["face_col"] = []
|
| 379 |
|