File size: 608 Bytes
d9fd056
 
160b840
d9fd056
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from fastapi import FastAPI, File, UploadFile
from predict_glaucoma import predict_glaucoma

import tempfile

app = FastAPI()

@app.post("/predict/")
async def predict(file: UploadFile = File(...)):
    model_path = "final_model.h5"

    # Salve a imagem em um arquivo temporário
    with tempfile.NamedTemporaryFile(suffix=".jpg") as tmp_file:
        tmp_file.write(await file.read())
        tmp_file.flush()

        # Faça a previsão usando a função 'predict_glaucoma'
        prediction = predict_glaucoma(tmp_file.name, model_path)
    
    return {"probabilidade_de_glaucoma": prediction * 100}