from fastapi import FastAPI, Request from fastapi.responses import HTMLResponse, JSONResponse import os, pathlib, json from Deployment_UI import router as deployment_ui_router from Deployment_UI_BE import router as deployment_be_router from modelblob import router as modelblob_router # NEW (blob page + /modelblob.json) app = FastAPI() app.include_router(deployment_ui_router) app.include_router(deployment_be_router) app.include_router(modelblob_router) # NEW LOCAL_BLOB_PATH = os.getenv("MODEL_BLOB_PATH", "/tmp/model_blob.json") def _load_blob_text() -> str: try: if os.path.exists(LOCAL_BLOB_PATH): return pathlib.Path(LOCAL_BLOB_PATH).read_text(encoding="utf-8") except Exception: pass return "{\n \"note\": \"paste or programmatically write the model blob to /tmp/model_blob.json\"\n}" def html_escape(s: str) -> str: return ( s.replace("&", "&") .replace("<", "<") .replace(">", ">") .replace('"', """) .replace("'", "'") ) @app.get("/", response_class=HTMLResponse) def landing_page() -> HTMLResponse: blob_text = _load_blob_text() html = f""" RunPod Model Tester — Blob

RunPod Model Tester — Blob

{len(blob_text)}
Model blob (read-only)
{html_escape(blob_text)}
Open Deployment UI
""" return HTMLResponse(html) # kept for compatibility but no longer used by the UI flow @app.post("/set_blob") async def set_blob(req: Request): try: ctype = req.headers.get("content-type","") if "application/json" in ctype: data = await req.json() txt = data.get("blob") if isinstance(data, dict) else None else: form = await req.form() txt = form.get("blob") if not isinstance(txt, str) or not txt.strip(): return JSONResponse({"error": "Missing 'blob' string"}, 400) pathlib.Path(LOCAL_BLOB_PATH).write_text(txt, encoding="utf-8") return JSONResponse({"ok": True, "path": LOCAL_BLOB_PATH}) except Exception as e: return JSONResponse({"error": str(e)}, 500)