Spaces:
Running on Zero
Running on Zero
banco Decision-2.0 CPU: agregar el snapshot a sys.path (trae el paquete decision2/) y reportar el dispositivo
Browse files
app.py
CHANGED
|
@@ -165,11 +165,17 @@ def _cargar() -> None:
|
|
| 165 |
global MODEL
|
| 166 |
if MODEL is not None:
|
| 167 |
return
|
|
|
|
|
|
|
| 168 |
from huggingface_hub import snapshot_download
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
from decision2 import Decision2
|
| 171 |
|
| 172 |
-
ruta = snapshot_download(MODELO)
|
| 173 |
MODEL = Decision2.from_pretrained(ruta, device="cpu")
|
| 174 |
|
| 175 |
|
|
@@ -240,9 +246,10 @@ def preparar(texto: str = "hola", reply_to: str = "", historial: str = "") -> di
|
|
| 240 |
r = MODEL.system_one(state=_estado(texto, reply_to, historial), questions=PREGUNTAS)
|
| 241 |
dt = time.perf_counter() - t1
|
| 242 |
d = _decidir(r.get("answers", {}))
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
"
|
|
|
|
| 246 |
except Exception as exc: # noqa: BLE001
|
| 247 |
return {"ok": False, "error": f"{type(exc).__name__}: {exc}",
|
| 248 |
"traceback": traceback.format_exc()[-1500:]}
|
|
|
|
| 165 |
global MODEL
|
| 166 |
if MODEL is not None:
|
| 167 |
return
|
| 168 |
+
import sys
|
| 169 |
+
|
| 170 |
from huggingface_hub import snapshot_download
|
| 171 |
|
| 172 |
+
ruta = snapshot_download(MODELO)
|
| 173 |
+
# Igual que con Clef: el snapshot trae el paquete `decision2/` pero no lo
|
| 174 |
+
# pone en sys.path, asi que hay que agregarlo a mano antes de importarlo.
|
| 175 |
+
if ruta not in sys.path:
|
| 176 |
+
sys.path.insert(0, ruta)
|
| 177 |
from decision2 import Decision2
|
| 178 |
|
|
|
|
| 179 |
MODEL = Decision2.from_pretrained(ruta, device="cpu")
|
| 180 |
|
| 181 |
|
|
|
|
| 246 |
r = MODEL.system_one(state=_estado(texto, reply_to, historial), questions=PREGUNTAS)
|
| 247 |
dt = time.perf_counter() - t1
|
| 248 |
d = _decidir(r.get("answers", {}))
|
| 249 |
+
dev = getattr(getattr(MODEL, "backend", None), "device", "?")
|
| 250 |
+
return {"ok": True, "modelo": MODELO, "dispositivo": str(dev),
|
| 251 |
+
"seg_carga": round(carga, 1), "ms_inferencia": int(dt * 1000),
|
| 252 |
+
"decision": d, "answers": r.get("answers")}
|
| 253 |
except Exception as exc: # noqa: BLE001
|
| 254 |
return {"ok": False, "error": f"{type(exc).__name__}: {exc}",
|
| 255 |
"traceback": traceback.format_exc()[-1500:]}
|