Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +304 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# app.py — MG360 (24 ítems) · Gradio Space
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
from typing import List, Dict, Tuple
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
import os, math, json, requests
|
| 8 |
+
|
| 9 |
+
# ========== Núcleo MG360 (24 ítems) ==========
|
| 10 |
+
@dataclass(frozen=True)
|
| 11 |
+
class Item:
|
| 12 |
+
code: str
|
| 13 |
+
text: str
|
| 14 |
+
dimension: str # "COG", "EMO", "REL", "EJE"
|
| 15 |
+
reverse: bool
|
| 16 |
+
|
| 17 |
+
ITEMS: List[Item] = [
|
| 18 |
+
# Cognitiva (COG)
|
| 19 |
+
Item("COG1", "Antes de decidir, evalúo cómo una acción afecta a otras áreas.", "COG", False),
|
| 20 |
+
Item("COG2", "Anticipo escenarios y consecuencias más allá del corto plazo.", "COG", False),
|
| 21 |
+
Item("COG3", "Identifico patrones y relaciones entre procesos aparentemente aislados.", "COG", False),
|
| 22 |
+
Item("COG4", "Prefiero concentrarme solo en mi área aunque desconozca las demás.", "COG", True),
|
| 23 |
+
Item("COG5", "Decido principalmente según urgencias del día a día.", "COG", True),
|
| 24 |
+
Item("COG6", "Me cuesta ver el impacto sistémico de mis decisiones.", "COG", True),
|
| 25 |
+
# Emocional (EMO)
|
| 26 |
+
Item("EMO1", "Identifico emociones que influyen en mi trato con otros.", "EMO", False),
|
| 27 |
+
Item("EMO2", "Regulo mi respuesta emocional aun bajo presión.", "EMO", False),
|
| 28 |
+
Item("EMO3", "Practico la empatía para comprender perspectivas distintas.", "EMO", False),
|
| 29 |
+
Item("EMO4", "Suelo reprimir emociones para no mostrar debilidad.", "EMO", True),
|
| 30 |
+
Item("EMO5", "Cuando me frustro, reacciono de forma impulsiva.", "EMO", True),
|
| 31 |
+
Item("EMO6", "Evito hablar de emociones en el trabajo.", "EMO", True),
|
| 32 |
+
# Relacional (REL)
|
| 33 |
+
Item("REL1", "Busco acuerdos que integren intereses distintos.", "REL", False),
|
| 34 |
+
Item("REL2", "Comunico expectativas de forma clara y verifico entendimiento.", "REL", False),
|
| 35 |
+
Item("REL3", "Fomento colaboración efectiva entre áreas y niveles.", "REL", False),
|
| 36 |
+
Item("REL4", "Evito confrontar para no generar conflicto.", "REL", True),
|
| 37 |
+
Item("REL5", "Prefiero trabajar de forma individual para avanzar más rápido.", "REL", True),
|
| 38 |
+
Item("REL6", "Me cuesta adaptar mi comunicación según el interlocutor.", "REL", True),
|
| 39 |
+
# Ejecucional (EJE)
|
| 40 |
+
Item("EJE1", "Transformo errores en oportunidades de aprendizaje.", "EJE", False),
|
| 41 |
+
Item("EJE2", "Cumplo compromisos en tiempo forma de manera consistente.", "EJE", False),
|
| 42 |
+
Item("EJE3", "Itero procesos para mejorar resultados de forma continua.", "EJE", False),
|
| 43 |
+
Item("EJE4", "Cumplir metas es más importante que desarrollar a las personas.", "EJE", True),
|
| 44 |
+
Item("EJE5", "Me desanimo fácilmente cuando surgen obstáculos.", "EJE", True),
|
| 45 |
+
Item("EJE6", "Evito revisar resultados para no encontrar fallas.", "EJE", True),
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
DIMENSIONS = ["COG", "EMO", "REL", "EJE"]
|
| 49 |
+
DIMENSION_LABELS = {
|
| 50 |
+
"COG": "Cognitiva",
|
| 51 |
+
"EMO": "Emocional",
|
| 52 |
+
"REL": "Relacional",
|
| 53 |
+
"EJE": "Ejecucional",
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
def invert_if_needed(value: float, reverse: bool) -> float:
|
| 57 |
+
return 6 - value if reverse else value
|
| 58 |
+
|
| 59 |
+
def score_responses(responses: Dict[str, float]) -> Dict[str, float]:
|
| 60 |
+
dim_values = {d: [] for d in DIMENSIONS}
|
| 61 |
+
for code, v in responses.items():
|
| 62 |
+
# Validación 1..5
|
| 63 |
+
fv = float(v)
|
| 64 |
+
if not (1 <= fv <= 5):
|
| 65 |
+
raise ValueError(f"Respuesta fuera de 1-5 en {code}: {fv}")
|
| 66 |
+
# Cálculo
|
| 67 |
+
for it in ITEMS:
|
| 68 |
+
v = float(responses[it.code])
|
| 69 |
+
dim_values[it.dimension].append(invert_if_needed(v, it.reverse))
|
| 70 |
+
dim_avg = {d: sum(vals)/len(vals) for d, vals in dim_values.items()}
|
| 71 |
+
vals = list(dim_avg.values())
|
| 72 |
+
avg = sum(vals)/len(vals)
|
| 73 |
+
var = sum((x-avg)**2 for x in vals) / len(vals)
|
| 74 |
+
stdev = (var ** 0.5)
|
| 75 |
+
balance_360 = 1 - (stdev / avg) if avg > 0 else 0.0
|
| 76 |
+
return {**dim_avg, "BALANCE_360": balance_360}
|
| 77 |
+
|
| 78 |
+
def dominant_axis(dim_scores: Dict[str, float]) -> Tuple[str, float]:
|
| 79 |
+
best_dim = max(DIMENSIONS, key=lambda d: dim_scores[d])
|
| 80 |
+
return best_dim, dim_scores[best_dim]
|
| 81 |
+
|
| 82 |
+
def interpret(dim_scores: Dict[str, float]) -> Dict[str, str]:
|
| 83 |
+
bal = dim_scores["BALANCE_360"]
|
| 84 |
+
if bal > 0.85:
|
| 85 |
+
eq = "Mentalidad 360 desarrollada"
|
| 86 |
+
elif bal >= 0.70:
|
| 87 |
+
eq = "Parcialmente equilibrada"
|
| 88 |
+
else:
|
| 89 |
+
eq = "Tendencia a sesgo gerencial (un eje domina)"
|
| 90 |
+
best, val = dominant_axis(dim_scores)
|
| 91 |
+
perfiles = {
|
| 92 |
+
"COG": "Estratega analítico (Cognitivo)",
|
| 93 |
+
"EMO": "Líder empático (Emocional)",
|
| 94 |
+
"REL": "Conector colaborativo (Relacional)",
|
| 95 |
+
"EJE": "Gestor ejecutor (Ejecucional)",
|
| 96 |
+
}
|
| 97 |
+
return {"equilibrio": eq, "eje_dominante": f"{perfiles[best]} — {DIMENSION_LABELS[best]} ({val:.2f}/5)"}
|
| 98 |
+
|
| 99 |
+
# ========== Radar limpio y simétrico ==========
|
| 100 |
+
def radar_plot(dim_scores: Dict[str, float], title: str, out_png: str) -> str:
|
| 101 |
+
import numpy as np
|
| 102 |
+
import matplotlib.pyplot as plt
|
| 103 |
+
|
| 104 |
+
DIM_ORDER = ["COG", "EMO", "REL", "EJE"]
|
| 105 |
+
labels = [DIMENSION_LABELS[d] for d in DIM_ORDER]
|
| 106 |
+
vals = [float(dim_scores[d]) for d in DIM_ORDER]
|
| 107 |
+
|
| 108 |
+
angles = np.linspace(0, 2*np.pi, len(labels), endpoint=False)
|
| 109 |
+
angles_cycle = np.concatenate([angles, [angles[0]]])
|
| 110 |
+
vals_cycle = np.concatenate([vals, [vals[0]]])
|
| 111 |
+
|
| 112 |
+
fig = plt.figure(figsize=(8, 8))
|
| 113 |
+
ax = plt.subplot(111, polar=True)
|
| 114 |
+
ax.set_facecolor("white")
|
| 115 |
+
fig.subplots_adjust(bottom=0.18)
|
| 116 |
+
|
| 117 |
+
ax.set_theta_offset(np.pi / 2)
|
| 118 |
+
ax.set_theta_direction(-1)
|
| 119 |
+
|
| 120 |
+
ax.set_xticks(angles)
|
| 121 |
+
ax.set_xticklabels(labels, fontsize=14, fontweight="bold")
|
| 122 |
+
|
| 123 |
+
ax.set_ylim(0, 5)
|
| 124 |
+
ax.set_yticks([1, 2, 3, 4, 5])
|
| 125 |
+
ax.set_yticklabels(["1", "2", "3", "4", "5"], fontsize=11)
|
| 126 |
+
ax.yaxis.grid(True, linewidth=0.8, alpha=0.6)
|
| 127 |
+
ax.xaxis.grid(True, linewidth=0.8, alpha=0.6)
|
| 128 |
+
|
| 129 |
+
ax.plot(angles_cycle, vals_cycle, linewidth=2.2)
|
| 130 |
+
ax.fill(angles_cycle, vals_cycle, alpha=0.18)
|
| 131 |
+
|
| 132 |
+
for ang, v in zip(angles, vals):
|
| 133 |
+
ax.plot([ang], [v], marker="o", markersize=6)
|
| 134 |
+
ax.text(ang, min(5, v + 0.22), f"{v:.2f}", ha="center", va="center", fontsize=11, fontweight="bold")
|
| 135 |
+
|
| 136 |
+
ax.set_title(title, fontsize=22, fontweight="bold", pad=18)
|
| 137 |
+
bal = float(dim_scores.get("BALANCE_360", 0.0))
|
| 138 |
+
dom = max(DIM_ORDER, key=lambda d: dim_scores[d])
|
| 139 |
+
subtitle = f"Balance 360: {bal:.3f} · Eje dominante: {DIMENSION_LABELS[dom]} ({dim_scores[dom]:.2f}/5)"
|
| 140 |
+
fig.text(0.5, 0.03, subtitle, ha="center", va="center", fontsize=11)
|
| 141 |
+
|
| 142 |
+
fig.tight_layout()
|
| 143 |
+
fig.savefig(out_png, dpi=240, bbox_inches="tight")
|
| 144 |
+
plt.close(fig)
|
| 145 |
+
return out_png
|
| 146 |
+
|
| 147 |
+
# ========== Prompt + LLM (Phi, InferenceClient) ==========
|
| 148 |
+
from huggingface_hub import InferenceClient
|
| 149 |
+
|
| 150 |
+
HF_MODEL_ID = os.environ.get("HF_MODEL_ID", "microsoft/Phi-3.5-mini-instruct")
|
| 151 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", None) # define esto en "Settings → Variables & secrets" del Space
|
| 152 |
+
|
| 153 |
+
def build_prompt(scores: Dict[str, float], inter: Dict[str, str]) -> str:
|
| 154 |
+
lines = [
|
| 155 |
+
"Eres un coach ejecutivo experto en ICB4 (People, Practice, Perspective).",
|
| 156 |
+
"Con base en el siguiente diagnóstico MG360 (1–5), genera un plan de desarrollo práctico, accionable y medible.",
|
| 157 |
+
"",
|
| 158 |
+
"Resultados por eje:",
|
| 159 |
+
f"- Cognitiva: {scores['COG']:.2f}/5",
|
| 160 |
+
f"- Emocional: {scores['EMO']:.2f}/5",
|
| 161 |
+
f"- Relacional: {scores['REL']:.2f}/5",
|
| 162 |
+
f"- Ejecucional:{scores['EJE']:.2f}/5",
|
| 163 |
+
f"- Balance 360: {scores['BALANCE_360']:.3f}",
|
| 164 |
+
f"- Interpretación: {inter['equilibrio']} | {inter['eje_dominante']}",
|
| 165 |
+
"",
|
| 166 |
+
"Instrucciones de salida:",
|
| 167 |
+
"1) Empieza con un resumen de 2–3 líneas del perfil.",
|
| 168 |
+
"2) Para cada eje (Cognitiva, Emocional, Relacional, Ejecucional):",
|
| 169 |
+
" - Da 3 acciones SMART (específicas, medibles, con plazos).",
|
| 170 |
+
" - Incluye 1 indicador sugerido y 1 hábito semanal.",
|
| 171 |
+
"3) Cierra con un plan de 30 días (semanas 1–4) y riesgos comunes.",
|
| 172 |
+
]
|
| 173 |
+
return "\\n".join(lines)
|
| 174 |
+
|
| 175 |
+
def generate_plan_with_phi(prompt: str) -> str:
|
| 176 |
+
# Sin token: devolvemos aviso (el usuario puede definir HF_TOKEN en Secrets)
|
| 177 |
+
if not HF_TOKEN:
|
| 178 |
+
return ("[Aviso] Falta HF_TOKEN. Configúralo como variable de entorno "
|
| 179 |
+
"en tu Space (Settings → Variables & secrets).")
|
| 180 |
+
|
| 181 |
+
# 1) Intento con InferenceClient
|
| 182 |
+
try:
|
| 183 |
+
client = InferenceClient(HF_MODEL_ID, token=HF_TOKEN, timeout=180)
|
| 184 |
+
out = client.text_generation(
|
| 185 |
+
prompt,
|
| 186 |
+
max_new_tokens=600,
|
| 187 |
+
do_sample=True,
|
| 188 |
+
temperature=0.7,
|
| 189 |
+
top_p=0.9,
|
| 190 |
+
repetition_penalty=1.05,
|
| 191 |
+
return_full_text=False,
|
| 192 |
+
)
|
| 193 |
+
return out.strip()
|
| 194 |
+
except Exception as e:
|
| 195 |
+
err1 = f"[InferenceClient] {type(e).__name__}: {e}"
|
| 196 |
+
|
| 197 |
+
# 2) Fallback vía REST
|
| 198 |
+
try:
|
| 199 |
+
url = f"https://api-inference.huggingface.co/models/{HF_MODEL_ID}"
|
| 200 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 201 |
+
payload = {
|
| 202 |
+
"inputs": prompt,
|
| 203 |
+
"parameters": {
|
| 204 |
+
"max_new_tokens": 600,
|
| 205 |
+
"do_sample": True,
|
| 206 |
+
"temperature": 0.7,
|
| 207 |
+
"top_p": 0.9,
|
| 208 |
+
"repetition_penalty": 1.05,
|
| 209 |
+
"return_full_text": False
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
r = requests.post(url, headers=headers, json=payload, timeout=180)
|
| 213 |
+
if r.status_code == 503:
|
| 214 |
+
return (f"[HF 503] El modelo {HF_MODEL_ID} está cargando o sin recurso. "
|
| 215 |
+
f"Detalle: {r.text}")
|
| 216 |
+
r.raise_for_status()
|
| 217 |
+
data = r.json()
|
| 218 |
+
if isinstance(data, list) and data and "generated_text" in data[0]:
|
| 219 |
+
return data[0]["generated_text"].strip()
|
| 220 |
+
if isinstance(data, dict) and "generated_text" in data:
|
| 221 |
+
return data["generated_text"].strip()
|
| 222 |
+
if isinstance(data, dict) and "error" in data:
|
| 223 |
+
return f"[HF error] {data.get('error')}"
|
| 224 |
+
return f"[HF respuesta inesperada] {json.dumps(data)[:400]}..."
|
| 225 |
+
except Exception as e2:
|
| 226 |
+
err2 = f"[REST] {type(e2).__name__}: {e2}"
|
| 227 |
+
return f"[Error al llamar al modelo {HF_MODEL_ID}]\\n{err1}\\n{err2}"
|
| 228 |
+
|
| 229 |
+
# ========== Utilidades Gradio ==========
|
| 230 |
+
def items_schema() -> List[Dict[str, str]]:
|
| 231 |
+
return [{"code": it.code, "text": it.text, "dimension": DIMENSION_LABELS[it.dimension], "reverse": it.reverse} for it in ITEMS]
|
| 232 |
+
|
| 233 |
+
def _ensure_outdir() -> Path:
|
| 234 |
+
out_dir = Path("mg360_resultados"); out_dir.mkdir(parents=True, exist_ok=True); return out_dir
|
| 235 |
+
|
| 236 |
+
def _evaluate_internal(res_vals: List[int]):
|
| 237 |
+
schema = items_schema()
|
| 238 |
+
responses = { schema[i]["code"]: int(res_vals[i]) for i in range(len(schema)) }
|
| 239 |
+
scores = score_responses(responses)
|
| 240 |
+
inter = interpret(scores)
|
| 241 |
+
|
| 242 |
+
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 243 |
+
out_dir = _ensure_outdir()
|
| 244 |
+
out_json = out_dir / f"mg360_reporte_{ts}.json"
|
| 245 |
+
out_png = out_dir / f"mg360_radar_{ts}.png"
|
| 246 |
+
radar_plot(scores, "Perfil MG360 (1–5)", str(out_png))
|
| 247 |
+
|
| 248 |
+
with open(out_json, "w", encoding="utf-8") as f:
|
| 249 |
+
json.dump({"responses": responses, "scores": scores, "interpretation": inter}, f, ensure_ascii=False, indent=2)
|
| 250 |
+
|
| 251 |
+
# Texto de resultados
|
| 252 |
+
md = [
|
| 253 |
+
"**Resultados**",
|
| 254 |
+
*(f"- {DIMENSION_LABELS[d]}: {scores[d]:.2f}/5" for d in ["COG","EMO","REL","EJE"]),
|
| 255 |
+
f"- **BALANCE 360**: {scores['BALANCE_360']:.3f}",
|
| 256 |
+
"",
|
| 257 |
+
"**Interpretación**",
|
| 258 |
+
f"- Equilibrio: {inter['equilibrio']}",
|
| 259 |
+
f"- Eje dominante: {inter['eje_dominante']}",
|
| 260 |
+
]
|
| 261 |
+
|
| 262 |
+
# Plan de desarrollo (IA)
|
| 263 |
+
plan_prompt = build_prompt(scores, inter)
|
| 264 |
+
plan_text = generate_plan_with_phi(plan_prompt)
|
| 265 |
+
|
| 266 |
+
return str(out_png), "\\n".join(md), json.dumps({"responses": responses, "scores": scores, "interpretation": inter}, ensure_ascii=False, indent=2), plan_text
|
| 267 |
+
|
| 268 |
+
# ========== App Gradio ==========
|
| 269 |
+
import gradio as gr
|
| 270 |
+
|
| 271 |
+
schema = items_schema()
|
| 272 |
+
with gr.Blocks() as demo:
|
| 273 |
+
gr.Markdown("# Test MG360 (24 ítems) — Versión Avanzada + Plan IA")
|
| 274 |
+
gr.Markdown("**Escala 1–5:** 1=**Nunca**, 2=**Rara vez**, 3=**A veces**, 4=**Frecuente**, 5=**Siempre**.")
|
| 275 |
+
|
| 276 |
+
with gr.Accordion("Cuestionario (24 ítems)", open=True):
|
| 277 |
+
gr.Markdown("### Guía de escala: 1=**Nunca** · 2=**Rara vez** · 3=**A veces** · 4=**Frecuente** · 5=**Siempre**")
|
| 278 |
+
sliders = [
|
| 279 |
+
gr.Slider(1, 5, step=1, value=3,
|
| 280 |
+
label=f"{it['code']} — {it['text']} (1 Nunca · 2 Rara vez · 3 A veces · 4 Frecuente · 5 Siempre)")
|
| 281 |
+
for it in schema
|
| 282 |
+
]
|
| 283 |
+
|
| 284 |
+
with gr.Row():
|
| 285 |
+
btn = gr.Button("Evaluar", scale=1)
|
| 286 |
+
model_id = gr.Textbox(value=HF_MODEL_ID, label="HF_MODEL_ID (opcional)", scale=3)
|
| 287 |
+
img = gr.Image(type="filepath", label="Radar 4D (1–5)")
|
| 288 |
+
md = gr.Markdown()
|
| 289 |
+
js = gr.Code(language="json", label="Reporte (JSON)")
|
| 290 |
+
plan= gr.Markdown(label="Plan de desarrollo (IA)")
|
| 291 |
+
|
| 292 |
+
def evaluate(*vals):
|
| 293 |
+
# Permitir override del modelo por UI (no persiste, solo en sesión)
|
| 294 |
+
global HF_MODEL_ID
|
| 295 |
+
vals=list(vals)
|
| 296 |
+
HF_MODEL_ID = vals.pop() or HF_MODEL_ID
|
| 297 |
+
return _evaluate_internal(vals)
|
| 298 |
+
|
| 299 |
+
inputs = sliders + [model_id]
|
| 300 |
+
btn.click(fn=evaluate, inputs=inputs, outputs=[img, md, js, plan])
|
| 301 |
+
|
| 302 |
+
# Para ejecución local:
|
| 303 |
+
if __name__ == "__main__":
|
| 304 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.44.0
|
| 2 |
+
huggingface_hub>=0.24.0
|
| 3 |
+
numpy>=1.26.0
|
| 4 |
+
matplotlib>=3.8.0
|
| 5 |
+
requests>=2.31.0
|