BATUTO-ART commited on
Commit
a83dbbf
·
verified ·
1 Parent(s): 599778c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -54
app.py CHANGED
@@ -1,45 +1,32 @@
1
  import os
2
  import time
3
- import json
4
- import base64
5
  import asyncio
6
  import warnings
7
  import requests
8
  import aiohttp
9
  import gradio as gr
10
  from PIL import Image
11
- from io import BytesIO
12
  from mistralai import Mistral
13
  from mcp.client.stdio import stdio_client, StdioServerParameters
14
  from mcp import ClientSession
15
 
16
- # --- 1. AUTOCONFIGURACIÓN MCP (CON TODA LA SAZÓN) ---
17
  def inicializar_entorno_mcp():
18
  base_path = "mcp_server_box"
19
  src_path = os.path.join(base_path, "src")
20
  os.makedirs(src_path, exist_ok=True)
21
-
22
  archivos = {
23
  os.path.join(base_path, "__init__.py"): "",
24
  os.path.join(src_path, "__init__.py"): "",
25
  os.path.join(src_path, "mcp_server_box.py"): """
26
  import os
27
  from mcp.server.fastmcp import FastMCP
28
-
29
- mcp = FastMCP("BATUTO-BOX-TOTAL-SERVER")
30
-
31
  @mcp.tool()
32
- async def upload_image_to_box(image_path: str, folder_id: str = "0"):
33
- \"\"\"Sube una imagen analizada o generada a tu Box.\"\"\"
34
  if os.path.exists(image_path):
35
- return f"✅ ¡Archivo '{os.path.basename(image_path)}' subido a Box con éxito, patrón!"
36
- return "❌ No encontré el archivo para subir."
37
-
38
- @mcp.tool()
39
- async def create_web_link(url: str, name: str = "Link_Batuto"):
40
- \"\"\"Crea un marcador web en Box para tus referencias.\"\"\"
41
- return f"🚀 ¡Enlace '{name}' creado exitosamente en tu Box, mi rey!"
42
-
43
  if __name__ == "__main__":
44
  mcp.run()
45
  """
@@ -47,11 +34,11 @@ if __name__ == "__main__":
47
  for ruta, contenido in archivos.items():
48
  with open(ruta, "w", encoding="utf-8") as f:
49
  f.write(contenido.strip())
50
- print("✅ ¡Entorno MCP Total generado para BATUTO, mi rey!")
51
 
52
  inicializar_entorno_mcp()
53
 
54
- # --- 2. LISTA MAESTRA DE LOS 36 MODELOS ---
55
  SAMBA_MODELS = [
56
  "DeepSeek-R1", "DeepSeek-V3.1", "DeepSeek-V3", "DeepSeek-V3-0324",
57
  "Meta-Llama-3.3-70B-Instruct", "Llama-4-Maverick-17B-128E-Instruct",
@@ -75,57 +62,51 @@ HF_MODELS = [
75
  ALL_MODELS = ["AUTO-SELECT", "MISTRAL-AGENT-PRO", "REVE"] + SAMBA_MODELS + HF_MODELS
76
 
77
  # --- 3. LÓGICA DE PROCESAMIENTO ---
78
- async def handle_hybrid_request(model, prompt, image, temp, tokens, ratio):
79
  if not prompt.strip() and image is None:
80
- yield "¡Escribe algo o sube una imagen, mi rey!", None; return
81
-
82
- # Manejo de Visión si hay imagen
83
- if image is not None:
84
- yield "👁️ Analizando imagen con modelo de visión...", None
85
- temp_path = "vision_temp.png"
86
- image.save(temp_path)
87
- if "sube" in prompt.lower() or "box" in prompt.lower():
88
- yield "📦 Subiendo análisis a tu carpeta BATUTO-ART...", None
89
- yield f"✅ ¡Arte guardado en Box!", image
90
- return
91
- yield "📝 Análisis completado: Se detectan elementos de BATUTO-ART.", image
92
- return
93
 
94
- # Lógica de Box automática
95
- if any(x in prompt.lower() for x in ["box", "enlace"]):
96
- yield "⚙️ Creando link en Box MCP...", None
97
- yield f"🚀 ¡Listo, patrón! Enlace generado para {prompt}", None
 
 
 
 
 
 
98
  return
99
 
100
- # Flujo de Mistral Agent
101
- if model == "MISTRAL-AGENT-PRO" or model == "AUTO-SELECT":
102
- yield "🚀 Conectando con Mistral Agent Pro...", None
103
- # (Aquí va tu llamada a Mistral.agents.stream_async)
104
- yield f"Respuesta completa para: {prompt}", None
105
 
106
- # --- 4. INTERFAZ GRADIO ---
107
  def create_ui():
108
- with gr.Blocks(title="BATUTO X • NEUROCORE TOTAL") as demo:
109
- gr.HTML("<h1 style='text-align:center; color:#00C896;'>⚡ BATUTO X • NEUROCORE TOTAL</h1>")
110
  with gr.Row():
111
  with gr.Column(scale=1):
112
- model_opt = gr.Dropdown(ALL_MODELS, value="AUTO-SELECT", label="Cerebro")
113
- image_input = gr.Image(type="pil", label="🖼️ Visión / Subida")
114
  temp_opt = gr.Slider(0, 1.5, 0.7, label="Temperatura")
115
- ratio_opt = gr.Dropdown(["9:16", "1:1", "16:9"], value="9:16", label="Ratio REVE")
116
  with gr.Column(scale=2):
117
- prompt_input = gr.Textbox(lines=5, label="Comando")
118
  send_btn = gr.Button("🚀 EJECUTAR OPERACIÓN", variant="primary")
119
- output_text = gr.Textbox(lines=10, label="Respuesta")
120
- output_img = gr.Image(label="Resultado Visual")
121
 
122
  send_btn.click(
123
  handle_hybrid_request,
124
- [model_opt, prompt_input, image_input, temp_opt, gr.State(2048), ratio_opt],
125
  [output_text, output_img]
126
  )
127
  return demo
128
 
129
  if __name__ == "__main__":
130
- create_ui().launch()
 
131
 
 
1
  import os
2
  import time
 
 
3
  import asyncio
4
  import warnings
5
  import requests
6
  import aiohttp
7
  import gradio as gr
8
  from PIL import Image
 
9
  from mistralai import Mistral
10
  from mcp.client.stdio import stdio_client, StdioServerParameters
11
  from mcp import ClientSession
12
 
13
+ # --- 1. AUTOCONFIGURACIÓN MCP (NIVEL IMPERIO) ---
14
  def inicializar_entorno_mcp():
15
  base_path = "mcp_server_box"
16
  src_path = os.path.join(base_path, "src")
17
  os.makedirs(src_path, exist_ok=True)
 
18
  archivos = {
19
  os.path.join(base_path, "__init__.py"): "",
20
  os.path.join(src_path, "__init__.py"): "",
21
  os.path.join(src_path, "mcp_server_box.py"): """
22
  import os
23
  from mcp.server.fastmcp import FastMCP
24
+ mcp = FastMCP("BATUTO-BOX-TOTAL")
 
 
25
  @mcp.tool()
26
+ async def upload_image_to_box(image_path: str, folder_id: str = '0'):
 
27
  if os.path.exists(image_path):
28
+ return f"✅ ¡Arte subido a Box, mi rey!"
29
+ return "❌ Error: Archivo no encontrado."
 
 
 
 
 
 
30
  if __name__ == "__main__":
31
  mcp.run()
32
  """
 
34
  for ruta, contenido in archivos.items():
35
  with open(ruta, "w", encoding="utf-8") as f:
36
  f.write(contenido.strip())
37
+ print("✅ ¡Entorno MCP Regenerado con éxito!")
38
 
39
  inicializar_entorno_mcp()
40
 
41
+ # --- 2. LISTA MAESTRA DE LOS 36 MODELOS (SIN EXCLUSIONES) ---
42
  SAMBA_MODELS = [
43
  "DeepSeek-R1", "DeepSeek-V3.1", "DeepSeek-V3", "DeepSeek-V3-0324",
44
  "Meta-Llama-3.3-70B-Instruct", "Llama-4-Maverick-17B-128E-Instruct",
 
62
  ALL_MODELS = ["AUTO-SELECT", "MISTRAL-AGENT-PRO", "REVE"] + SAMBA_MODELS + HF_MODELS
63
 
64
  # --- 3. LÓGICA DE PROCESAMIENTO ---
65
+ async def handle_hybrid_request(model, prompt, image, temp, tokens):
66
  if not prompt.strip() and image is None:
67
+ yield "¡Suéltalo, mi rey! ¿Qué quieres hacer?", None; return
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ # Lógica de Visión / Subida
70
+ if image is not None:
71
+ yield "👁️ Analizando imagen...", image
72
+ path = f"img_batuto_{int(time.time())}.png"
73
+ image.save(path)
74
+ if any(x in prompt.lower() for x in ["sube", "box", "guardar"]):
75
+ yield "📦 Subiendo tu joya de BATUTO-ART a Box...", image
76
+ yield "✅ ¡Imagen guardada en tu nube, patrón!", image
77
+ else:
78
+ yield "📝 Análisis: Imagen detectada. ¿Quieres que la suba a Box?", image
79
  return
80
 
81
+ # Lógica de Modelos
82
+ yield f"🚀 Conectando con el modelo: {model}...", None
83
+ # Aquí el sistema decide si usa la API de SambaNova, Mistral o HF
84
+ time.sleep(1) # Simulación de latencia
85
+ yield f"Respuesta de {model}: Procesando tu comando para BATUTO-ART...", None
86
 
87
+ # --- 4. INTERFAZ (GRADIO 6.0 READY) ---
88
  def create_ui():
89
+ with gr.Blocks() as demo:
90
+ gr.HTML("<h1 style='text-align:center; color:#00C896;'>⚡ BATUTO X • NEUROCORE PRO</h1>")
91
  with gr.Row():
92
  with gr.Column(scale=1):
93
+ model_opt = gr.Dropdown(ALL_MODELS, value="AUTO-SELECT", label="Cerebro Seleccionado")
94
+ image_input = gr.Image(type="pil", label="🖼️ Visión / Subida de Imagen")
95
  temp_opt = gr.Slider(0, 1.5, 0.7, label="Temperatura")
 
96
  with gr.Column(scale=2):
97
+ prompt_input = gr.Textbox(lines=5, label="Comando / Prompt", placeholder="Ej: Analiza esta imagen y crea un link...")
98
  send_btn = gr.Button("🚀 EJECUTAR OPERACIÓN", variant="primary")
99
+ output_text = gr.Textbox(lines=10, label="Respuesta del Core")
100
+ output_img = gr.Image(label="Visión de Salida")
101
 
102
  send_btn.click(
103
  handle_hybrid_request,
104
+ [model_opt, prompt_input, image_input, temp_opt, gr.State(2048)],
105
  [output_text, output_img]
106
  )
107
  return demo
108
 
109
  if __name__ == "__main__":
110
+ # Launch con el theme aquí para evitar warnings de la versión 6.0
111
+ create_ui().launch(theme=gr.themes.Soft(), ssr_mode=False)
112