Spaces:
Build error
Build error
Commit ·
6fa74f8
1
Parent(s): 356abdb
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,46 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def classify_image(inp):
|
| 8 |
-
inp = inp.reshape((-1,
|
| 9 |
prediction = new_model.predict(inp).flatten()
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
-
gr.Interface(
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
| 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[1]
|
| 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 |
+
print(new_model.predict(inp))
|
| 24 |
+
if len(prediction) > 1:
|
| 25 |
+
probability = 100 * math.exp(prediction[1]) / (math.exp(prediction[0]) + math.exp(prediction[1]))
|
| 26 |
+
else:
|
| 27 |
+
probability = round(100. / (1 + math.exp(-prediction[0])), 2)
|
| 28 |
+
if probability > 45:
|
| 29 |
+
return "Glaucoma", probability
|
| 30 |
+
if probability > 25:
|
| 31 |
+
return "Unclear", probability
|
| 32 |
+
return "Not glaucoma", probability
|
| 33 |
|
| 34 |
|
| 35 |
+
gr.Interface(
|
| 36 |
+
fn=classify_image,
|
| 37 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
| 38 |
+
outputs=[
|
| 39 |
+
gr.outputs.Textbox(label="Label"),
|
| 40 |
+
gr.outputs.Textbox(label="Glaucoma probability (0 - 100)"),
|
| 41 |
+
],
|
| 42 |
+
examples=["001.jpg", "002.jpg", "225.jpg"],
|
| 43 |
+
flagging_options=["Correct label", "Incorrect label"],
|
| 44 |
+
allow_flagging="manual",
|
| 45 |
+
).launch()
|
| 46 |
|