Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,45 @@
|
|
| 1 |
-
|
| 2 |
-
from predict_glaucoma import predict_glaucoma
|
| 3 |
|
| 4 |
-
import
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
async def predict(file: UploadFile = File(...)):
|
| 10 |
-
model_path = "final_model.h5"
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
# Faça a previsão usando a função 'predict_glaucoma'
|
| 18 |
-
prediction = predict_glaucoma(tmp_file.name, model_path)
|
| 19 |
-
|
| 20 |
-
return {"probabilidade_de_glaucoma": prediction * 100}
|
|
|
|
| 1 |
+
import math
|
|
|
|
| 2 |
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import tensorflow as tf
|
| 5 |
|
| 6 |
+
configs = [
|
| 7 |
+
{
|
| 8 |
+
"model": "my_model_2.h5", "size": 512
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"model": "my_model.h5", "size": 224
|
| 12 |
+
},
|
| 13 |
+
]
|
| 14 |
|
| 15 |
+
config = configs[0]
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
new_model = tf.keras.models.load_model(config["model"])
|
| 18 |
+
|
| 19 |
+
def classify_image(inp):
|
| 20 |
+
inp = inp.reshape((-1, config["size"], config["size"], 3))
|
| 21 |
+
prediction = new_model.predict(inp).flatten()
|
| 22 |
+
print(prediction)
|
| 23 |
+
if len(prediction) > 1:
|
| 24 |
+
probability = 100 * math.exp(prediction[0]) / (math.exp(prediction[0]) + math.exp(prediction[1]))
|
| 25 |
+
else:
|
| 26 |
+
probability = round(100. / (1 + math.exp(-prediction[0])), 2)
|
| 27 |
+
if probability > 45:
|
| 28 |
+
return "Glaucoma", probability
|
| 29 |
+
if probability > 25:
|
| 30 |
+
return "Unclear", probability
|
| 31 |
+
return "Not glaucoma", probability
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
gr.Interface(
|
| 35 |
+
fn=classify_image,
|
| 36 |
+
inputs=gr.inputs.Image(shape=(config["size"], config["size"])),
|
| 37 |
+
outputs=[
|
| 38 |
+
gr.outputs.Textbox(label="Label"),
|
| 39 |
+
gr.outputs.Textbox(label="Glaucoma probability (0 - 100)"),
|
| 40 |
+
],
|
| 41 |
+
examples=["001.jpg", "002.jpg", "225.jpg"],
|
| 42 |
+
flagging_options=["Correct label", "Incorrect label"],
|
| 43 |
+
allow_flagging="manual",
|
| 44 |
+
).launch()
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|