CoolFace
Apppublic

CouchPotato101/prostate_detection_backend

sourceHugging Facemitupdated 10mo agoView on Hugging Face
0likes
app.py35 linesDownload Raw Back to past_code
1import os2import tempfile3from fastapi import FastAPI, UploadFile, File4from model_loader import load_model5from inference import predict_image6 7app = FastAPI(8    title="Prostate Cancer Detection API",9    description="FastAPI backend using EfficientNet-B0 to predict prostate cancer grade",10    version="1.0"11)12 13MODEL_PATH = "model/how_to_train_effnet_b0_to_get_LB_0.86_final_fold0.pth"14 15 16@app.on_event("startup")17def load():18    load_model(MODEL_PATH)19 20 21@app.post("/predict")22async def predict(file: UploadFile = File(...)):23    # Save temp file24    with tempfile.NamedTemporaryFile(delete=False, suffix=".tiff") as tmp:25        tmp.write(await file.read())26        tmp_path = tmp.name27 28    result = predict_image(tmp_path)29    os.remove(tmp_path)30 31    return {32        "filename": file.filename,33        "prediction": result34    }35