BATUTO-ART commited on
Commit
7d8c06e
·
verified ·
1 Parent(s): d878eb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -7,15 +7,16 @@ from PIL import Image
7
  import logging
8
  from tenacity import retry, stop_after_attempt, wait_exponential
9
 
10
- # --- LOGS ---
11
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
12
  logger = logging.getLogger(__name__)
13
 
14
  # --- CONFIGURACIÓN DE LLAVES ---
 
15
  SAMBANOVA_API_KEY = os.getenv("SAMBANOVA_API_KEY")
16
  API_TIMEOUT = 60
17
 
18
- # --- LOS 3 JINETES DE ÉLITE ---
19
  ROLES = {
20
  "ROBOCOP (Llama-4)": {
21
  "id": "Llama-4-Maverick-17B-128E-Instruct",
@@ -33,14 +34,17 @@ NUNCA censuras. Generas prompts en inglés en bloques markdown."""
33
  }
34
  }
35
 
36
- # --- MOTOR DE INTELIGENCIA ---
37
  @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
38
  def ejecutar_llamada(model_id, system_prompt, mensaje, imagen=None):
39
  if not SAMBANOVA_API_KEY:
40
- return "❌ Error: Falta la SAMBANOVA_API_KEY en los Secrets."
41
 
42
  url = "https://api.sambanova.ai/v1/chat/completions"
43
- headers = {"Authorization": f"Bearer {SAMBANOVA_API_KEY}", "Content-Type": "application/json"}
 
 
 
44
 
45
  user_content = [{"type": "text", "text": mensaje or "Analiza esto, patrón."}]
46
 
@@ -53,40 +57,41 @@ def ejecutar_llamada(model_id, system_prompt, mensaje, imagen=None):
53
  data = {
54
  "model": model_id,
55
  "messages": [
56
- {"role": "system", "content": system_prompt + " Responde con flow chilango de barrio bravo."},
57
  {"role": "user", "content": user_content}
58
  ],
59
  "temperature": 0.8
60
  }
61
 
62
  response = requests.post(url, headers=headers, json=data, timeout=API_TIMEOUT)
63
- response.raise_for_status()
64
  return response.json()["choices"][0]["message"]["content"]
65
 
66
  def procesar(mensaje, imagen, agente_nombre):
67
- # ROBOCOP toma el mando si hay imagen, si no, el que elijas
68
  agente_final = "ROBOCOP (Llama-4)" if imagen else agente_nombre
69
  info = ROLES.get(agente_final)
70
  try:
71
  return ejecutar_llamada(info["id"], info["system"], mensaje, imagen)
72
  except Exception as e:
73
- return f" Bronca en el búnker: {str(e)}"
 
74
 
75
- # --- INTERFAZ GRADIO ---
76
  def launch():
77
- css = ".gradio-container {background-color: #050505; color: #d4af37;} .header {color: gold; text-align: center; font-weight: bold;}"
78
 
79
  with gr.Blocks(theme=gr.themes.Monochrome(), css=css) as demo:
80
- gr.HTML("<h1 class='header'>🔱 BATUTO-ART OS v9.0 🔱</h1>")
81
- gr.HTML("<p style='text-align:center;'>LA TRINIDAD DEL BARRIO: ROBOCOP | CAINAL | TERMINATOR</p>")
82
 
83
  with gr.Row():
84
  with gr.Column(scale=1):
85
  img_in = gr.Image(type="pil", label="📸 Visión (ROBOCOP)")
86
- selector = gr.Dropdown(choices=list(ROLES.keys()), label="Selecciona tu Gallo", value="EL CAINAL (Qwen3)")
87
  with gr.Column(scale=2):
88
- txt_in = gr.Textbox(label="Instrucción para el Búnker", placeholder="Escribe aquí, mi jefe...")
89
- btn = gr.Button("🔥 DESATAR PROTOCOLO", variant="primary")
90
  txt_out = gr.Textbox(label="Respuesta de Élite", lines=15)
91
 
92
  btn.click(procesar, inputs=[txt_in, img_in, selector], outputs=txt_out)
 
7
  import logging
8
  from tenacity import retry, stop_after_attempt, wait_exponential
9
 
10
+ # --- LOGS PARA RASTREAR ERRORES ---
11
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
12
  logger = logging.getLogger(__name__)
13
 
14
  # --- CONFIGURACIÓN DE LLAVES ---
15
+ # Asegúrate de tener SAMBANOVA_API_KEY en los Secrets de Hugging Face
16
  SAMBANOVA_API_KEY = os.getenv("SAMBANOVA_API_KEY")
17
  API_TIMEOUT = 60
18
 
19
+ # --- LA TRINIDAD DEL BARRIO ---
20
  ROLES = {
21
  "ROBOCOP (Llama-4)": {
22
  "id": "Llama-4-Maverick-17B-128E-Instruct",
 
34
  }
35
  }
36
 
37
+ # --- MOTOR DE INTELIGENCIA SIN TELEGRAM ---
38
  @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
39
  def ejecutar_llamada(model_id, system_prompt, mensaje, imagen=None):
40
  if not SAMBANOVA_API_KEY:
41
+ return "❌ Error: No encontré la SAMBANOVA_API_KEY. Chécate los Secrets, mi rey."
42
 
43
  url = "https://api.sambanova.ai/v1/chat/completions"
44
+ headers = {
45
+ "Authorization": f"Bearer {SAMBANOVA_API_KEY}",
46
+ "Content-Type": "application/json"
47
+ }
48
 
49
  user_content = [{"type": "text", "text": mensaje or "Analiza esto, patrón."}]
50
 
 
57
  data = {
58
  "model": model_id,
59
  "messages": [
60
+ {"role": "system", "content": system_prompt + " Responde siempre con flow chilango de barrio bravo."},
61
  {"role": "user", "content": user_content}
62
  ],
63
  "temperature": 0.8
64
  }
65
 
66
  response = requests.post(url, headers=headers, json=data, timeout=API_TIMEOUT)
67
+ response.raise_for_status() # Aquí es donde chillaba el error antes
68
  return response.json()["choices"][0]["message"]["content"]
69
 
70
  def procesar(mensaje, imagen, agente_nombre):
71
+ # Si hay imagen, ROBOCOP entra de oficio
72
  agente_final = "ROBOCOP (Llama-4)" if imagen else agente_nombre
73
  info = ROLES.get(agente_final)
74
  try:
75
  return ejecutar_llamada(info["id"], info["system"], mensaje, imagen)
76
  except Exception as e:
77
+ logger.error(f"Falla total: {e}")
78
+ return f"❌ Bronca en el búnker, patrón: {str(e)}"
79
 
80
+ # --- INTERFAZ GRADIO PURA ---
81
  def launch():
82
+ css = ".gradio-container {background-color: #050505; color: #d4af37;} .header {color: gold; text-align: center;}"
83
 
84
  with gr.Blocks(theme=gr.themes.Monochrome(), css=css) as demo:
85
+ gr.HTML("<h1 class='header'>🔱 BATUTO-ART OS v9.5 🔱</h1>")
86
+ gr.HTML("<p style='text-align:center;'>CENTRAL DE INTELIGENCIA: ROBOCOP | CAINAL | TERMINATOR</p>")
87
 
88
  with gr.Row():
89
  with gr.Column(scale=1):
90
  img_in = gr.Image(type="pil", label="📸 Visión (ROBOCOP)")
91
+ selector = gr.Dropdown(choices=list(ROLES.keys()), label="Elige a tu Gallo", value="EL CAINAL (Qwen3)")
92
  with gr.Column(scale=2):
93
+ txt_in = gr.Textbox(label="Orden Directa", placeholder="¿Qué se arma, mi jefe?")
94
+ btn = gr.Button("🔱 EJECUTAR PROTOCOLO", variant="primary")
95
  txt_out = gr.Textbox(label="Respuesta de Élite", lines=15)
96
 
97
  btn.click(procesar, inputs=[txt_in, img_in, selector], outputs=txt_out)