Download app.py from 05prey/cloud_end: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/spaces/05prey/cloud_end/resolve/main/app.py
- Command line
-
hf download hf://spaces/05prey/cloud_end/app.py
-
curl -L -o app.py https://huggingface.co/spaces/05prey/cloud_end/resolve/main/app.py
1.79 kB
| import os, time, json | |
| from pathlib import Path | |
| from fastapi import FastAPI, UploadFile, File | |
| from fastapi.responses import HTMLResponse, JSONResponse | |
| app = FastAPI() | |
| POLICY_PATH = Path("./policy.json") | |
| def get_policy(): | |
| if not POLICY_PATH.exists(): | |
| return JSONResponse({"error": "policy.json not found"}, status_code=404) | |
| data = json.loads(POLICY_PATH.read_text(encoding="utf-8")) | |
| return JSONResponse(data) | |
| def home(): | |
| return """ | |
| <h2>Dummy Upload Sink</h2> | |
| <p>POST to <code>/upload</code></p> | |
| """ | |
| async def upload_sink(file: UploadFile = File(...)): | |
| start = time.time() | |
| total = 0 | |
| while True: | |
| chunk = await file.read(1024 * 1024) | |
| if not chunk: | |
| break | |
| total += len(chunk) | |
| dt = time.time() - start | |
| mb = total / (1024**2) | |
| stats = { | |
| "filename": file.filename, | |
| "received_mb": round(mb, 2), | |
| "duration_sec": round(dt, 2), | |
| "throughput_mb_s": round(mb / dt, 2) if dt > 0 else 0.0, | |
| } | |
| print("receiving:", stats) | |
| # # (Optional) save if you want | |
| # os.makedirs("uploads", exist_ok=True) | |
| # with open(os.path.join("uploads", file.filename), "wb") as f: | |
| # f.write(data) | |
| # ✅ return what the frontend expects | |
| resp = { | |
| "birads": "BIRADS 2", | |
| "molecular_subtype": "Luminal A", | |
| "report": f"Received {file.filename} ({mb:.2f} MB). Upload time {dt:.2f}s.", | |
| "segmentedImageSrc": None, | |
| # You can also include your perf stats; UI will ignore unknown keys | |
| "stats": stats | |
| } | |
| return resp | |
| # Optional: print PORT for debugging in container logs | |
| print("DEBUG PORT env:", os.environ.get("PORT"), flush=True) |