Tu Nombre commited on
Commit
3eea0e3
·
1 Parent(s): 4bbf43d

feat: sistema de nichos automatico por PDF

Browse files
Files changed (3) hide show
  1. app.py +6 -3
  2. ltx_service.py +6 -3
  3. nichos.py +55 -0
app.py CHANGED
@@ -17,9 +17,9 @@ try:
17
  from ltx_service import generar_clips_escenas as generar_ltx
18
  except Exception:
19
  def generar_ltx(escenas): return None
20
- def generar_clips_escenas(escenas):
21
  import copy
22
- res = generar_ltx(copy.deepcopy(escenas))
23
  if res and any(str(e.get("material", "")).startswith("ltx_") for e in res): return res
24
  print("[Cerebro] LTX no disponible. Saltando a Runway...", flush=True)
25
  res = generar_runway(copy.deepcopy(escenas))
@@ -493,7 +493,10 @@ async def ep_video(request: Request):
493
  # Usamos tus archivos de forma circular si hay menos que escenas
494
  e["material"] = ESTADO["archivos"][idx % len(ESTADO["archivos"])]
495
  if not ESTADO["archivos"]:
496
- escenas = generar_clips_escenas(escenas)
 
 
 
497
  # Lista de (material, segundos) de cada escena, en orden
498
  escenas_data = [(e.get("material",""), int(e.get("segundos",5) or 5)) for e in escenas]
499
  material_escenas = [m for m,s in escenas_data if m]
 
17
  from ltx_service import generar_clips_escenas as generar_ltx
18
  except Exception:
19
  def generar_ltx(escenas): return None
20
+ def generar_clips_escenas(escenas, nicho="espiritualidad"):
21
  import copy
22
+ res = generar_ltx(copy.deepcopy(escenas), nicho=nicho)
23
  if res and any(str(e.get("material", "")).startswith("ltx_") for e in res): return res
24
  print("[Cerebro] LTX no disponible. Saltando a Runway...", flush=True)
25
  res = generar_runway(copy.deepcopy(escenas))
 
493
  # Usamos tus archivos de forma circular si hay menos que escenas
494
  e["material"] = ESTADO["archivos"][idx % len(ESTADO["archivos"])]
495
  if not ESTADO["archivos"]:
496
+ from nichos import detectar_nicho
497
+ nicho_detectado = detectar_nicho(guion)
498
+ print(f"[Fenix] Nicho detectado: {nicho_detectado}", flush=True)
499
+ escenas = generar_clips_escenas(escenas, nicho=nicho_detectado)
500
  # Lista de (material, segundos) de cada escena, en orden
501
  escenas_data = [(e.get("material",""), int(e.get("segundos",5) or 5)) for e in escenas]
502
  material_escenas = [m for m,s in escenas_data if m]
ltx_service.py CHANGED
@@ -8,12 +8,13 @@ if _SPACE_ID:
8
  else:
9
  print("[LTX] Falta LTX_SPACE_ID (se salta este motor)", flush=True)
10
 
11
- def _crear_prompt_groq(texto):
12
  try:
13
  from groq import Groq
14
  keys = [k for k in [os.environ.get("GROQ_KEY",""), os.environ.get("GROQ_KEY_2",""), os.environ.get("GROQ_KEY_3","")] if k]
15
  if not keys: return texto
16
  prompt = f"""You are a cinematic prompt engineer. Convert this scene into a vivid English video prompt.
 
17
  Rules:
18
  1. Be 100% LITERAL to the objects, people and actions described. If it says blue car arriving at school, write exactly that.
19
  2. Always add: bright natural lighting, vibrant colors, ultra detailed, 8K, cinematic shot.
@@ -66,7 +67,9 @@ def _conectar():
66
  print("[LTX] Timeout de arranque.", flush=True)
67
  return None
68
 
69
- def generar_clips_escenas(escenas):
 
 
70
  if not _SPACE_ID: return None
71
  client = _conectar()
72
  if not client: return None
@@ -76,7 +79,7 @@ def generar_clips_escenas(escenas):
76
  mat = e.get("material","").strip()
77
  seg = int(e.get("segundos",5) or 5)
78
  if not mat and txt and gen < _MAX_CLIPS:
79
- pv = _crear_prompt_groq(txt)
80
  print(f"[LTX] Escena {i+1}: {pv}", flush=True)
81
  try:
82
  t = time.time()
 
8
  else:
9
  print("[LTX] Falta LTX_SPACE_ID (se salta este motor)", flush=True)
10
 
11
+ def _crear_prompt_groq(texto, estilo_nicho=''):
12
  try:
13
  from groq import Groq
14
  keys = [k for k in [os.environ.get("GROQ_KEY",""), os.environ.get("GROQ_KEY_2",""), os.environ.get("GROQ_KEY_3","")] if k]
15
  if not keys: return texto
16
  prompt = f"""You are a cinematic prompt engineer. Convert this scene into a vivid English video prompt.
17
+ Niche visual style to apply: {estilo_nicho}.
18
  Rules:
19
  1. Be 100% LITERAL to the objects, people and actions described. If it says blue car arriving at school, write exactly that.
20
  2. Always add: bright natural lighting, vibrant colors, ultra detailed, 8K, cinematic shot.
 
67
  print("[LTX] Timeout de arranque.", flush=True)
68
  return None
69
 
70
+ def generar_clips_escenas(escenas, nicho='espiritualidad'):
71
+ from nichos import get_estilo
72
+ estilo_nicho = get_estilo(nicho)['estilo']
73
  if not _SPACE_ID: return None
74
  client = _conectar()
75
  if not client: return None
 
79
  mat = e.get("material","").strip()
80
  seg = int(e.get("segundos",5) or 5)
81
  if not mat and txt and gen < _MAX_CLIPS:
82
+ pv = _crear_prompt_groq(txt, estilo_nicho)
83
  print(f"[LTX] Escena {i+1}: {pv}", flush=True)
84
  try:
85
  t = time.time()
nichos.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ NICHOS = {
2
+ "espiritualidad": {
3
+ "keywords": ["alma", "espiritu", "dios", "consciencia", "despertar", "numerologia", "gematria", "hebreo", "sagrado", "mistica", "oracion", "fe", "luz divina"],
4
+ "estilo": "ethereal mystical atmosphere, golden divine light rays, soft glowing particles, sacred geometry, cinematic slow zoom, ultra detailed 8K",
5
+ "camara": "slow zoom in, gentle orbital shot",
6
+ "color": "golden, warm amber, soft white light"
7
+ },
8
+ "negocios": {
9
+ "keywords": ["exito", "empresa", "negocio", "dinero", "emprendedor", "ventas", "cliente", "marketing", "liderazgo", "productividad"],
10
+ "estilo": "modern professional environment, clean bright office, confident people, sharp cinematic lighting, ultra detailed 8K",
11
+ "camara": "smooth pan, slow push in",
12
+ "color": "blue, white, gold accents"
13
+ },
14
+ "salud": {
15
+ "keywords": ["salud", "bienestar", "cuerpo", "mente", "meditacion", "yoga", "nutricion", "ejercicio", "energia", "equilibrio"],
16
+ "estilo": "serene natural environment, fresh morning light, vibrant green nature, peaceful atmosphere, cinematic slow zoom, ultra detailed 8K",
17
+ "camara": "slow zoom in, smooth pan",
18
+ "color": "green, soft white, natural tones"
19
+ },
20
+ "amor": {
21
+ "keywords": ["amor", "pareja", "relacion", "corazon", "enamorado", "familia", "conexion", "sentimiento", "romance"],
22
+ "estilo": "warm romantic atmosphere, soft bokeh lights, golden hour sunset, intimate cinematic shot, ultra detailed 8K",
23
+ "camara": "slow zoom in, gentle pan",
24
+ "color": "warm pink, gold, soft orange"
25
+ },
26
+ "finanzas": {
27
+ "keywords": ["dinero", "inversion", "bolsa", "cripto", "riqueza", "ahorro", "financiero", "mercado", "capital", "patrimonio"],
28
+ "estilo": "sleek financial environment, city skyline at night, data visualization, sharp dramatic lighting, cinematic ultra detailed 8K",
29
+ "camara": "orbital shot, slow push in",
30
+ "color": "dark blue, gold, green accents"
31
+ },
32
+ "misterio": {
33
+ "keywords": ["misterio", "conspiracion", "oculto", "secreto", "verdad", "illuminati", "gobierno", "matrix", "realidad"],
34
+ "estilo": "dark dramatic atmosphere, cinematic shadows, mysterious fog, dramatic contrast lighting, slow orbit camera, ultra detailed 8K",
35
+ "camara": "slow orbit, dramatic push in",
36
+ "color": "dark, deep purple, red accents"
37
+ },
38
+ "coaching": {
39
+ "keywords": ["coaching", "transformacion", "habitos", "mentalidad", "potencial", "crecimiento", "personal", "proposito", "metas"],
40
+ "estilo": "inspiring bright environment, motivated person, dramatic natural lighting, empowering cinematic shot, ultra detailed 8K",
41
+ "camara": "slow zoom in, smooth pan",
42
+ "color": "orange, white, bright tones"
43
+ }
44
+ }
45
+
46
+ def detectar_nicho(texto):
47
+ texto_lower = texto.lower()
48
+ puntos = {}
49
+ for nicho, data in NICHOS.items():
50
+ puntos[nicho] = sum(1 for kw in data["keywords"] if kw in texto_lower)
51
+ mejor = max(puntos, key=puntos.get)
52
+ return mejor if puntos[mejor] > 0 else "espiritualidad"
53
+
54
+ def get_estilo(nicho):
55
+ return NICHOS.get(nicho, NICHOS["espiritualidad"])