Upload 6 files
Browse files
page_modules/process_video.py
CHANGED
|
@@ -846,95 +846,6 @@ def render_process_video_page(api, backend_base_url: str) -> None:
|
|
| 846 |
print(f"[SVISION] Error complet: {e}")
|
| 847 |
import traceback
|
| 848 |
traceback.print_exc()
|
| 849 |
-
name_key = f"{key_prefix}_name"
|
| 850 |
-
desc_key = f"{key_prefix}_desc"
|
| 851 |
-
default_scene_name = sc.get("name", "")
|
| 852 |
-
default_scene_desc = sc.get("description", "")
|
| 853 |
-
|
| 854 |
-
if default_scene_name and (name_key not in st.session_state or not st.session_state.get(name_key)):
|
| 855 |
-
st.session_state[name_key] = default_scene_name
|
| 856 |
-
elif name_key not in st.session_state:
|
| 857 |
-
st.session_state[name_key] = default_scene_name or ""
|
| 858 |
-
|
| 859 |
-
if default_scene_desc and (desc_key not in st.session_state or not st.session_state.get(desc_key)):
|
| 860 |
-
st.session_state[desc_key] = default_scene_desc
|
| 861 |
-
elif desc_key not in st.session_state:
|
| 862 |
-
st.session_state[desc_key] = default_scene_desc or ""
|
| 863 |
-
|
| 864 |
-
pending_desc_key = f"{key_prefix}_pending_desc"
|
| 865 |
-
pending_name_key = f"{key_prefix}_pending_name"
|
| 866 |
-
if pending_desc_key in st.session_state:
|
| 867 |
-
if desc_key not in st.session_state:
|
| 868 |
-
st.session_state[desc_key] = ""
|
| 869 |
-
st.session_state[desc_key] = st.session_state[pending_desc_key]
|
| 870 |
-
del st.session_state[pending_desc_key]
|
| 871 |
-
|
| 872 |
-
if pending_name_key in st.session_state:
|
| 873 |
-
if name_key not in st.session_state:
|
| 874 |
-
st.session_state[name_key] = ""
|
| 875 |
-
if not st.session_state.get(name_key):
|
| 876 |
-
st.session_state[name_key] = st.session_state[pending_name_key]
|
| 877 |
-
del st.session_state[pending_name_key]
|
| 878 |
-
|
| 879 |
-
st.text_input("Nom del clúster", key=name_key)
|
| 880 |
-
st.text_area("Descripció", key=desc_key, height=80)
|
| 881 |
-
|
| 882 |
-
if st.button("🎨 Generar descripció amb Salamandra Vision", key=f"svision_{key_prefix}"):
|
| 883 |
-
with st.spinner("Generant descripció..."):
|
| 884 |
-
from api_client import describe_image_with_svision, generate_short_scene_name
|
| 885 |
-
import requests as _req
|
| 886 |
-
import os as _os
|
| 887 |
-
import tempfile
|
| 888 |
-
|
| 889 |
-
try:
|
| 890 |
-
resp = _req.get(img_url, timeout=10)
|
| 891 |
-
if resp.status_code == 200:
|
| 892 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
|
| 893 |
-
tmp.write(resp.content)
|
| 894 |
-
tmp_path = tmp.name
|
| 895 |
-
|
| 896 |
-
try:
|
| 897 |
-
desc, name = describe_image_with_svision(tmp_path, is_face=False)
|
| 898 |
-
|
| 899 |
-
if desc:
|
| 900 |
-
st.session_state[pending_desc_key] = desc
|
| 901 |
-
print(f"[SVISION] Descripció d'escena generada per {scene_id}: {desc[:100]}")
|
| 902 |
-
|
| 903 |
-
try:
|
| 904 |
-
short_name = generate_short_scene_name(desc)
|
| 905 |
-
if short_name:
|
| 906 |
-
st.session_state[pending_name_key] = short_name
|
| 907 |
-
print(f"[SCHAT] Nom curt generat: {short_name}")
|
| 908 |
-
elif name:
|
| 909 |
-
st.session_state[pending_name_key] = name
|
| 910 |
-
print(f"[SVISION] Usant nom original: {name}")
|
| 911 |
-
except Exception as schat_err:
|
| 912 |
-
print(f"[SCHAT] Error: {schat_err}")
|
| 913 |
-
if name:
|
| 914 |
-
st.session_state[pending_name_key] = name
|
| 915 |
-
print(f"[SVISION] Usant nom original fallback: {name}")
|
| 916 |
-
|
| 917 |
-
st.success("✅ Descripció i nom generats!")
|
| 918 |
-
else:
|
| 919 |
-
st.warning("⚠️ No s'ha pogut generar una descripció.")
|
| 920 |
-
print(f"[SVISION] Descripció d'escena buida per {scene_id}")
|
| 921 |
-
|
| 922 |
-
finally:
|
| 923 |
-
# Always clean up the temp file
|
| 924 |
-
try:
|
| 925 |
-
_os.unlink(tmp_path)
|
| 926 |
-
except Exception as cleanup_err:
|
| 927 |
-
print(f"[SVISION] Error netejant fitxer temporal: {cleanup_err}")
|
| 928 |
-
|
| 929 |
-
st.rerun()
|
| 930 |
-
else:
|
| 931 |
-
st.error(f"No s'ha pogut descarregar la imatge (status: {resp.status_code})")
|
| 932 |
-
|
| 933 |
-
except Exception as e:
|
| 934 |
-
st.error(f"Error generant descripció: {str(e)}")
|
| 935 |
-
print(f"[SVISION] Error complet: {e}")
|
| 936 |
-
import traceback
|
| 937 |
-
traceback.print_exc()
|
| 938 |
|
| 939 |
# --- 6. Confirmación de casting y personajes combinados ---
|
| 940 |
if st.session_state.get("detect_done"):
|
|
|
|
| 846 |
print(f"[SVISION] Error complet: {e}")
|
| 847 |
import traceback
|
| 848 |
traceback.print_exc()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 849 |
|
| 850 |
# --- 6. Confirmación de casting y personajes combinados ---
|
| 851 |
if st.session_state.get("detect_done"):
|