File size: 1,788 Bytes
cc677ba
 
084a82a
cc677ba
084a82a
 
 
b6b4b26
cc677ba
 
 
 
 
 
 
 
 
 
084a82a
 
 
 
879ba95
084a82a
 
 
 
 
 
 
879ba95
084a82a
 
 
 
 
 
fb033f4
084a82a
 
 
 
 
8b03718
fb033f4
 
 
 
 
 
 
 
 
 
 
4866ec9
fb033f4
 
 
 
 
cf8c1e4
879ba95
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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")

@app.get("/policy")
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)



@app.get("/", response_class=HTMLResponse)
def home():
    return """
    <h2>Dummy Upload Sink</h2>
    <p>POST to <code>/upload</code></p>
    """

@app.post("/upload")
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)