Upload 2 files
Browse files- api_client.py +16 -0
- app.py +22 -0
api_client.py
CHANGED
|
@@ -167,6 +167,22 @@ class APIClient:
|
|
| 167 |
except requests.exceptions.RequestException as e:
|
| 168 |
return {"error": str(e)}
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
def rebuild_video_with_ad(self, video_path: str, srt_path: str) -> dict:
|
| 171 |
"""
|
| 172 |
Llama al space 'tts' para reconstruir un vídeo con audiodescripció a partir de un SRT.
|
|
|
|
| 167 |
except requests.exceptions.RequestException as e:
|
| 168 |
return {"error": str(e)}
|
| 169 |
|
| 170 |
+
def load_casting(self, faces_dir: str, voices_dir: str, db_dir: str, drop_collections: bool = False) -> dict:
|
| 171 |
+
"""Carga índices de caras y voces al motor de búsqueda Chroma del engine."""
|
| 172 |
+
url = f"{self.base_url}/load_casting"
|
| 173 |
+
data = {
|
| 174 |
+
"faces_dir": faces_dir,
|
| 175 |
+
"voices_dir": voices_dir,
|
| 176 |
+
"db_dir": db_dir,
|
| 177 |
+
"drop_collections": str(1 if drop_collections else 0),
|
| 178 |
+
}
|
| 179 |
+
try:
|
| 180 |
+
r = self.session.post(url, data=data, timeout=self.timeout * 5)
|
| 181 |
+
r.raise_for_status()
|
| 182 |
+
return r.json()
|
| 183 |
+
except requests.exceptions.RequestException as e:
|
| 184 |
+
return {"error": str(e)}
|
| 185 |
+
|
| 186 |
def rebuild_video_with_ad(self, video_path: str, srt_path: str) -> dict:
|
| 187 |
"""
|
| 188 |
Llama al space 'tts' para reconstruir un vídeo con audiodescripció a partir de un SRT.
|
app.py
CHANGED
|
@@ -448,6 +448,28 @@ if page == "Processar vídeo nou":
|
|
| 448 |
res_fc = api.finalize_casting(payload)
|
| 449 |
if isinstance(res_fc, dict) and res_fc.get("ok"):
|
| 450 |
st.success(f"Càsting consolidat. Identities: {len(res_fc.get('face_identities', []))} cares, {len(res_fc.get('voice_identities', []))} veus.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
else:
|
| 452 |
st.error(f"No s'ha pogut consolidar el càsting: {res_fc}")
|
| 453 |
with colc2:
|
|
|
|
| 448 |
res_fc = api.finalize_casting(payload)
|
| 449 |
if isinstance(res_fc, dict) and res_fc.get("ok"):
|
| 450 |
st.success(f"Càsting consolidat. Identities: {len(res_fc.get('face_identities', []))} cares, {len(res_fc.get('voice_identities', []))} veus.")
|
| 451 |
+
# Mostrar llistes
|
| 452 |
+
f_id = res_fc.get('face_identities', []) or []
|
| 453 |
+
v_id = res_fc.get('voice_identities', []) or []
|
| 454 |
+
c3, c4 = st.columns(2)
|
| 455 |
+
with c3:
|
| 456 |
+
st.markdown("**Identitats de cara**")
|
| 457 |
+
for n in f_id:
|
| 458 |
+
st.write(f"- {n}")
|
| 459 |
+
with c4:
|
| 460 |
+
st.markdown("**Identitats de veu**")
|
| 461 |
+
for n in v_id:
|
| 462 |
+
st.write(f"- {n}")
|
| 463 |
+
# Botó per carregar els índexs al buscador
|
| 464 |
+
faces_dir = res_fc.get('faces_dir')
|
| 465 |
+
voices_dir = res_fc.get('voices_dir')
|
| 466 |
+
db_dir = res_fc.get('db_dir')
|
| 467 |
+
if st.button("Carregar índexs al cercador (Chroma)"):
|
| 468 |
+
load_res = api.load_casting(faces_dir=faces_dir, voices_dir=voices_dir, db_dir=db_dir, drop_collections=True)
|
| 469 |
+
if isinstance(load_res, dict) and load_res.get('ok'):
|
| 470 |
+
st.success(f"Índexs carregats: {load_res.get('faces', 0)} cares, {load_res.get('voices', 0)} veus.")
|
| 471 |
+
else:
|
| 472 |
+
st.error(f"Error carregant índexs: {load_res}")
|
| 473 |
else:
|
| 474 |
st.error(f"No s'ha pogut consolidar el càsting: {res_fc}")
|
| 475 |
with colc2:
|