Spaces:
Sleeping
Sleeping
Update Deployment_UI_BE.py
Browse files- Deployment_UI_BE.py +38 -8
Deployment_UI_BE.py
CHANGED
|
@@ -152,6 +152,7 @@ def _normalize_blob_url(u: str | None) -> str | None:
|
|
| 152 |
u = str(u).strip()
|
| 153 |
if u.startswith(("http://", "https://")):
|
| 154 |
return u
|
|
|
|
| 155 |
if u.startswith("/"):
|
| 156 |
return f"{_LOCAL_BASE}{u}"
|
| 157 |
return f"{_LOCAL_BASE}/{u}"
|
|
@@ -169,7 +170,6 @@ def _fetch_url(u: str):
|
|
| 169 |
def _fetch_blob_from_page():
|
| 170 |
return _fetch_url(f"{_LOCAL_BASE}/modelblob.json")
|
| 171 |
|
| 172 |
-
# --- UPDATED: healthRoute + predictRoute caching ---
|
| 173 |
def _ingest_blob(parsed: dict, model_id_hint: str = "", container_image_hint: str = ""):
|
| 174 |
if not isinstance(parsed, dict):
|
| 175 |
raise HTTPException(400, "Invalid blob (expected JSON object).")
|
|
@@ -189,15 +189,45 @@ def _ingest_blob(parsed: dict, model_id_hint: str = "", container_image_hint: st
|
|
| 189 |
_INST[k] = v.strip()
|
| 190 |
|
| 191 |
image_uri = (c.get("imageUri") or "").strip().lower()
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
if not _INST.get("
|
| 196 |
-
_INST["
|
| 197 |
-
if not _INST.get("healthRoute"):
|
| 198 |
-
_INST["healthRoute"] = hr_hint or "/health"
|
| 199 |
|
| 200 |
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
# ---------------------------------------------------------------------
|
| 202 |
# Create instance
|
| 203 |
# ---------------------------------------------------------------------
|
|
|
|
| 152 |
u = str(u).strip()
|
| 153 |
if u.startswith(("http://", "https://")):
|
| 154 |
return u
|
| 155 |
+
# Treat '/x' or 'x' as local to this app (same origin as FE)
|
| 156 |
if u.startswith("/"):
|
| 157 |
return f"{_LOCAL_BASE}{u}"
|
| 158 |
return f"{_LOCAL_BASE}/{u}"
|
|
|
|
| 170 |
def _fetch_blob_from_page():
|
| 171 |
return _fetch_url(f"{_LOCAL_BASE}/modelblob.json")
|
| 172 |
|
|
|
|
| 173 |
def _ingest_blob(parsed: dict, model_id_hint: str = "", container_image_hint: str = ""):
|
| 174 |
if not isinstance(parsed, dict):
|
| 175 |
raise HTTPException(400, "Invalid blob (expected JSON object).")
|
|
|
|
| 189 |
_INST[k] = v.strip()
|
| 190 |
|
| 191 |
image_uri = (c.get("imageUri") or "").strip().lower()
|
| 192 |
+
pr, hr = _infer_routes_from_image(image_uri)
|
| 193 |
+
if pr and not _INST.get("predictRoute"):
|
| 194 |
+
_INST["predictRoute"] = pr
|
| 195 |
+
if hr and not _INST.get("healthRoute"):
|
| 196 |
+
_INST["healthRoute"] = hr # <-- only addition: cache healthRoute hint
|
|
|
|
|
|
|
| 197 |
|
| 198 |
return True
|
| 199 |
+
|
| 200 |
+
@router.post("/api/ingest/from_landing")
|
| 201 |
+
def api_ingest_from_landing(blob_url: str | None = None):
|
| 202 |
+
"""
|
| 203 |
+
Ingest the deployment blob for downstream use.
|
| 204 |
+
Mirrors FE behavior: resolve relative paths like '/modelblob.json'
|
| 205 |
+
against the app origin.
|
| 206 |
+
"""
|
| 207 |
+
u = _normalize_blob_url(blob_url) or _normalize_blob_url("/modelblob.json")
|
| 208 |
+
parsed = _fetch_url(u)
|
| 209 |
+
if not parsed:
|
| 210 |
+
return JSONResponse({"error": "Blob not available"}, 404)
|
| 211 |
+
_ingest_blob(parsed, model_id_hint="", container_image_hint="")
|
| 212 |
+
return JSONResponse({"ok": True, "source": u})
|
| 213 |
+
|
| 214 |
+
# (Optional compatibility: UI posting to /Deployment_UI; accepts blob_url via query)
|
| 215 |
+
@router.post("/Deployment_UI")
|
| 216 |
+
async def deployment_ui_ingest(request: Request,
|
| 217 |
+
model_id: str = Form(""),
|
| 218 |
+
container_image: str = Form(""),
|
| 219 |
+
blob: str = Form("")):
|
| 220 |
+
"""
|
| 221 |
+
Legacy entry used by the Deployment UI page.
|
| 222 |
+
Prefers blob_url from query string; falls back to the modelblob page JSON.
|
| 223 |
+
"""
|
| 224 |
+
blob_url = request.query_params.get("blob_url")
|
| 225 |
+
u = _normalize_blob_url(blob_url) if blob_url else _normalize_blob_url("/modelblob.json")
|
| 226 |
+
parsed = _fetch_url(u)
|
| 227 |
+
if not parsed:
|
| 228 |
+
return HTMLResponse("<pre>Missing blob (no /modelblob.json and no blob_url)</pre>", 400)
|
| 229 |
+
_ingest_blob(parsed, model_id_hint=model_id, container_image_hint=container_image)
|
| 230 |
+
return RedirectResponse("/Deployment_UI", 303)
|
| 231 |
# ---------------------------------------------------------------------
|
| 232 |
# Create instance
|
| 233 |
# ---------------------------------------------------------------------
|