Spaces:
Sleeping
Sleeping
Update Deployment_UI_BE.py
Browse files- Deployment_UI_BE.py +18 -7
Deployment_UI_BE.py
CHANGED
|
@@ -146,6 +146,17 @@ def _discover_route(base_url: str):
|
|
| 146 |
_HF_SPACE_PORT = os.getenv("PORT", "7860")
|
| 147 |
_LOCAL_BASE = f"http://127.0.0.1:{_HF_SPACE_PORT}"
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
def _fetch_url(u: str):
|
| 150 |
try:
|
| 151 |
r = requests.get(u, timeout=8)
|
|
@@ -163,15 +174,15 @@ def _fetch_blob_from_page():
|
|
| 163 |
def api_ingest_from_landing(blob_url: str | None = None):
|
| 164 |
"""
|
| 165 |
Ingest the deployment blob for downstream use.
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
2) local modelblob page JSON outlet
|
| 169 |
"""
|
| 170 |
-
|
|
|
|
| 171 |
if not parsed:
|
| 172 |
return JSONResponse({"error": "Blob not available"}, 404)
|
| 173 |
_ingest_blob(parsed, model_id_hint="", container_image_hint="")
|
| 174 |
-
return JSONResponse({"ok": True, "source":
|
| 175 |
|
| 176 |
# (Optional compatibility: UI posting to /Deployment_UI; accepts blob_url via query)
|
| 177 |
@router.post("/Deployment_UI")
|
|
@@ -184,12 +195,12 @@ async def deployment_ui_ingest(request: Request,
|
|
| 184 |
Prefers blob_url from query string; falls back to the modelblob page JSON.
|
| 185 |
"""
|
| 186 |
blob_url = request.query_params.get("blob_url")
|
| 187 |
-
|
|
|
|
| 188 |
if not parsed:
|
| 189 |
return HTMLResponse("<pre>Missing blob (no /modelblob.json and no blob_url)</pre>", 400)
|
| 190 |
_ingest_blob(parsed, model_id_hint=model_id, container_image_hint=container_image)
|
| 191 |
return RedirectResponse("/Deployment_UI", 303)
|
| 192 |
-
|
| 193 |
# ---------------------------------------------------------------------
|
| 194 |
# Create instance
|
| 195 |
# ---------------------------------------------------------------------
|
|
|
|
| 146 |
_HF_SPACE_PORT = os.getenv("PORT", "7860")
|
| 147 |
_LOCAL_BASE = f"http://127.0.0.1:{_HF_SPACE_PORT}"
|
| 148 |
|
| 149 |
+
def _normalize_blob_url(u: str | None) -> str | None:
|
| 150 |
+
if not u:
|
| 151 |
+
return None
|
| 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}"
|
| 159 |
+
|
| 160 |
def _fetch_url(u: str):
|
| 161 |
try:
|
| 162 |
r = requests.get(u, timeout=8)
|
|
|
|
| 174 |
def api_ingest_from_landing(blob_url: str | None = None):
|
| 175 |
"""
|
| 176 |
Ingest the deployment blob for downstream use.
|
| 177 |
+
Mirrors FE behavior: resolve relative paths like '/modelblob.json'
|
| 178 |
+
against the app origin.
|
|
|
|
| 179 |
"""
|
| 180 |
+
u = _normalize_blob_url(blob_url) or _normalize_blob_url("/modelblob.json")
|
| 181 |
+
parsed = _fetch_url(u)
|
| 182 |
if not parsed:
|
| 183 |
return JSONResponse({"error": "Blob not available"}, 404)
|
| 184 |
_ingest_blob(parsed, model_id_hint="", container_image_hint="")
|
| 185 |
+
return JSONResponse({"ok": True, "source": u})
|
| 186 |
|
| 187 |
# (Optional compatibility: UI posting to /Deployment_UI; accepts blob_url via query)
|
| 188 |
@router.post("/Deployment_UI")
|
|
|
|
| 195 |
Prefers blob_url from query string; falls back to the modelblob page JSON.
|
| 196 |
"""
|
| 197 |
blob_url = request.query_params.get("blob_url")
|
| 198 |
+
u = _normalize_blob_url(blob_url) if blob_url else _normalize_blob_url("/modelblob.json")
|
| 199 |
+
parsed = _fetch_url(u)
|
| 200 |
if not parsed:
|
| 201 |
return HTMLResponse("<pre>Missing blob (no /modelblob.json and no blob_url)</pre>", 400)
|
| 202 |
_ingest_blob(parsed, model_id_hint=model_id, container_image_hint=container_image)
|
| 203 |
return RedirectResponse("/Deployment_UI", 303)
|
|
|
|
| 204 |
# ---------------------------------------------------------------------
|
| 205 |
# Create instance
|
| 206 |
# ---------------------------------------------------------------------
|