VeuReu commited on
Commit
e9c6cef
verified
1 Parent(s): 5c22d4f

Upload api.py

Browse files
Files changed (1) hide show
  1. api.py +7 -55
api.py CHANGED
@@ -51,7 +51,7 @@ jobs: Dict[str, dict] = {}
51
 
52
  def describe_image_with_svision(image_path: str, is_face: bool = True) -> tuple[str, str]:
53
  """
54
- Llama al space svision para describir una imagen (cara o escena).
55
 
56
  Args:
57
  image_path: Ruta absoluta a la imagen
@@ -80,12 +80,12 @@ def describe_image_with_svision(image_path: str, is_face: bool = True) -> tuple[
80
  if is_face:
81
  context = {
82
  "task": "describe_person",
83
- "instructions": "Describe la persona en la imagen. Incluye: edad aproximada (joven/adulto), g茅nero, caracter铆sticas f铆sicas notables (gafas, barba, bigote, etc.), expresi贸n y vestimenta."
84
  }
85
  else:
86
  context = {
87
  "task": "describe_scene",
88
- "instructions": "Describe la escena en la imagen. Incluye: tipo de locaci贸n (interior/exterior), elementos principales, ambiente, iluminaci贸n."
89
  }
90
 
91
  # Llamar a svision
@@ -95,45 +95,12 @@ def describe_image_with_svision(image_path: str, is_face: bool = True) -> tuple[
95
  if not full_description:
96
  return ("", "")
97
 
98
- # Generar nombre abreviado para caras
99
- if is_face:
100
- # Extraer caracter铆sticas clave para el nombre
101
- desc_lower = full_description.lower()
102
-
103
- # Determinar edad y g茅nero
104
- is_young = any(word in desc_lower for word in ["joven", "ni帽o", "ni帽a", "adolescente", "chico", "chica"])
105
- is_female = any(word in desc_lower for word in ["mujer", "chica", "ni帽a", "femenin"])
106
-
107
- if is_young:
108
- base_name = "Chica" if is_female else "Chico"
109
- else:
110
- base_name = "Mujer" if is_female else "Hombre"
111
-
112
- # A帽adir caracter铆sticas distintivas
113
- features = []
114
- if "gafa" in desc_lower:
115
- features.append("gafas")
116
- if "barba" in desc_lower:
117
- features.append("barba")
118
- if "bigote" in desc_lower:
119
- features.append("bigote")
120
-
121
- if features:
122
- short_name = f"{base_name} con {', '.join(features)}"
123
- else:
124
- short_name = base_name
125
- else:
126
- # Para escenas, extraer primeras palabras clave
127
- words = full_description.split()[:4]
128
- short_name = " ".join(words).capitalize()
129
-
130
- print(f"[svision] Descripci贸n generada: {full_description[:100]}...")
131
- print(f"[svision] Nombre: {short_name}")
132
 
133
- return (full_description, short_name)
134
 
135
  except Exception as e:
136
- print(f"[svision] Error al describir imagen: {e}")
137
  import traceback
138
  traceback.print_exc()
139
  return ("", "")
@@ -585,24 +552,9 @@ def process_video_job(job_id: str):
585
  _sh.copy2(rep_src, rep_dst)
586
  except Exception:
587
  pass
588
- # Llamar a svision para describir la cara representativa
589
- description = ""
590
- short_name = f"Personatge {ci+1}"
591
- if rep:
592
- rep_full_path = out_dir / "representative.jpg"
593
- if rep_full_path.exists():
594
- print(f"[{job_id}] Llamando a svision para describir {char_id}...")
595
- try:
596
- description, short_name = describe_image_with_svision(str(rep_full_path), is_face=True)
597
- if not short_name:
598
- short_name = f"Personatge {ci+1}"
599
- except Exception as e:
600
- print(f"[{job_id}] Error describiendo {char_id}: {e}")
601
-
602
  characters.append({
603
  "id": char_id,
604
- "name": short_name,
605
- "description": description,
606
  "folder": str(out_dir),
607
  "num_faces": len(files),
608
  "image_url": f"/files/{video_name}/{char_id}/representative.jpg" if rep else "",
 
51
 
52
  def describe_image_with_svision(image_path: str, is_face: bool = True) -> tuple[str, str]:
53
  """
54
+ Llama al space svision para describir una imagen (usado en generaci贸n de AD).
55
 
56
  Args:
57
  image_path: Ruta absoluta a la imagen
 
80
  if is_face:
81
  context = {
82
  "task": "describe_person",
83
+ "instructions": "Descriu la persona en la imatge. Inclou: edat aproximada (jove/adult), g猫nere, caracter铆stiques f铆siques notables (ulleres, barba, bigoti, etc.), expressi贸 i vestimenta."
84
  }
85
  else:
86
  context = {
87
  "task": "describe_scene",
88
+ "instructions": "Descriu l'escena en la imatge. Inclou: tipus de localitzaci贸 (interior/exterior), elements principals, ambient, il路luminaci贸."
89
  }
90
 
91
  # Llamar a svision
 
95
  if not full_description:
96
  return ("", "")
97
 
98
+ print(f"[svision] Descripci贸 generada: {full_description[:100]}...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
+ return (full_description, "")
101
 
102
  except Exception as e:
103
+ print(f"[svision] Error al descriure imatge: {e}")
104
  import traceback
105
  traceback.print_exc()
106
  return ("", "")
 
552
  _sh.copy2(rep_src, rep_dst)
553
  except Exception:
554
  pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
555
  characters.append({
556
  "id": char_id,
557
+ "name": f"Personatge {ci+1}",
 
558
  "folder": str(out_dir),
559
  "num_faces": len(files),
560
  "image_url": f"/files/{video_name}/{char_id}/representative.jpg" if rep else "",