Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,33 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
import gradio as gr
|
4 |
import tensorflow as tf
|
5 |
|
6 |
-
|
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(
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
if len(prediction) > 1:
|
24 |
-
probability = 100 *
|
25 |
else:
|
26 |
-
probability = round(100. / (1 +
|
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 |
-
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()
|
|
|
1 |
+
import numpy as np
|
|
|
2 |
import gradio as gr
|
3 |
import tensorflow as tf
|
4 |
|
5 |
+
models = [ {"name": "my_model_2.h5", "size": 512}, {"name": "my_model.h5", "size": 224},]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def classify_image(image, model_name):
|
8 |
+
model_config = next(m for m in models if m["name"] == model_name)
|
9 |
+
model = tf.keras.models.load_model(model_name)
|
10 |
+
input_image = np.expand_dims(image, axis=0)
|
11 |
+
prediction = model.predict(input_image).flatten()
|
12 |
if len(prediction) > 1:
|
13 |
+
probability = 100 * np.exp(prediction[0]) / (np.exp(prediction[0]) + np.exp(prediction[1]))
|
14 |
else:
|
15 |
+
probability = round(100. / (1 + np.exp(-prediction[0])), 2)
|
16 |
if probability > 45:
|
17 |
+
label = "Glaucoma"
|
18 |
+
elif probability > 25:
|
19 |
+
label = "Unclear"
|
20 |
+
else:
|
21 |
+
label = "Not glaucoma"
|
22 |
+
return label, probability
|
23 |
|
24 |
+
inputs = [
|
25 |
+
gr.inputs.Image(shape=(224, 224), label="Eye image"),
|
26 |
+
gr.inputs.Dropdown(choices=[m["name"] for m in models], label="Model"),
|
27 |
+
]
|
28 |
+
outputs = [
|
29 |
+
gr.outputs.Textbox(label="Predicted label"),
|
30 |
+
gr.outputs.Textbox(label="Probability of glaucoma (0-100)"),
|
31 |
+
]
|
32 |
|
33 |
+
gr.Interface(classify_image, inputs, outputs, examples=["001.jpg", "002.jpg", "225.jpg"]).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|