Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import math
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import tensorflow as tf
|
| 4 |
|
|
@@ -12,36 +13,32 @@ configs = [
|
|
| 12 |
]
|
| 13 |
|
| 14 |
config = configs[0]
|
| 15 |
-
new_model = tf.keras.models.load_model(config["model"])
|
| 16 |
|
| 17 |
-
|
| 18 |
-
entrada = entrada.reshape((-1, config["size"], config["size"], 3))
|
| 19 |
-
prediction = new_model.predict(entrada).flatten()
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
if len(prediction) > 1:
|
| 22 |
-
|
| 23 |
else:
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
if probabilidade > 45:
|
| 27 |
-
label = "Glaucoma"
|
| 28 |
-
elif probabilidade > 25:
|
| 29 |
-
label = "Incerto"
|
| 30 |
-
else:
|
| 31 |
-
label = "N茫o glaucoma"
|
| 32 |
-
|
| 33 |
-
return {"R贸tulo": label, "Probabilidade de glaucoma (0 - 100)": probabilidade}
|
| 34 |
|
| 35 |
-
|
| 36 |
-
fn=
|
| 37 |
inputs=gr.inputs.Image(shape=(config["size"], config["size"])),
|
| 38 |
outputs=[
|
| 39 |
-
|
| 40 |
-
|
| 41 |
],
|
| 42 |
examples=["001.jpg", "002.jpg", "225.jpg"],
|
| 43 |
-
flagging_options=["
|
| 44 |
-
allow_flagging="manual"
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
interface.launch()
|
|
|
|
| 1 |
import math
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
import tensorflow as tf
|
| 5 |
|
|
|
|
| 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()
|
|
|
|
|
|