Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import math
|
2 |
-
|
3 |
import gradio as gr
|
4 |
import tensorflow as tf
|
5 |
|
@@ -19,27 +18,31 @@ new_model = tf.keras.models.load_model(config["model"])
|
|
19 |
def classify_image(inp):
|
20 |
inp = inp.reshape((-1, config["size"], config["size"], 3))
|
21 |
prediction = new_model.predict(inp).flatten()
|
22 |
-
|
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 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
32 |
|
|
|
33 |
|
34 |
-
gr.Interface(
|
35 |
fn=classify_image,
|
36 |
inputs=gr.inputs.Image(shape=(config["size"], config["size"])),
|
37 |
outputs=[
|
38 |
-
|
39 |
-
|
40 |
],
|
41 |
examples=["001.jpg", "002.jpg", "225.jpg"],
|
42 |
flagging_options=["Correct label", "Incorrect label"],
|
43 |
-
allow_flagging="manual"
|
44 |
-
)
|
45 |
|
|
|
|
1 |
import math
|
|
|
2 |
import gradio as gr
|
3 |
import tensorflow as tf
|
4 |
|
|
|
18 |
def classify_image(inp):
|
19 |
inp = inp.reshape((-1, config["size"], config["size"], 3))
|
20 |
prediction = new_model.predict(inp).flatten()
|
21 |
+
|
22 |
if len(prediction) > 1:
|
23 |
probability = 100 * math.exp(prediction[0]) / (math.exp(prediction[0]) + math.exp(prediction[1]))
|
24 |
else:
|
25 |
probability = round(100. / (1 + math.exp(-prediction[0])), 2)
|
26 |
+
|
27 |
if probability > 45:
|
28 |
+
label = "Glaucoma"
|
29 |
+
elif probability > 25:
|
30 |
+
label = "Unclear"
|
31 |
+
else:
|
32 |
+
label = "Not glaucoma"
|
33 |
|
34 |
+
return {"Label": label, "Glaucoma probability (0 - 100)": probability}
|
35 |
|
36 |
+
iface = gr.Interface(
|
37 |
fn=classify_image,
|
38 |
inputs=gr.inputs.Image(shape=(config["size"], config["size"])),
|
39 |
outputs=[
|
40 |
+
gr.outputs.Textbox(label="Label"),
|
41 |
+
gr.outputs.Textbox(label="Glaucoma probability (0 - 100)")
|
42 |
],
|
43 |
examples=["001.jpg", "002.jpg", "225.jpg"],
|
44 |
flagging_options=["Correct label", "Incorrect label"],
|
45 |
+
allow_flagging="manual"
|
46 |
+
)
|
47 |
|
48 |
+
iface.launch()
|