Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, File, UploadFile
|
2 |
+
from predict_glaucoma import predict_glaucoma
|
3 |
+
import tempfile
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
@app.post("/predict/")
|
8 |
+
async def predict(file: UploadFile = File(...)):
|
9 |
+
model_path = "final_model.h5"
|
10 |
+
|
11 |
+
# Salve a imagem em um arquivo temporário
|
12 |
+
with tempfile.NamedTemporaryFile(suffix=".jpg") as tmp_file:
|
13 |
+
tmp_file.write(await file.read())
|
14 |
+
tmp_file.flush()
|
15 |
+
|
16 |
+
# Faça a previsão usando a função 'predict_glaucoma'
|
17 |
+
prediction = predict_glaucoma(tmp_file.name, model_path)
|
18 |
+
|
19 |
+
return {"probabilidade_de_glaucoma": prediction * 100}
|