Spaces:
Sleeping
Sleeping
two pages
Browse files
app.py
CHANGED
@@ -40,42 +40,51 @@ model_binary = tf.keras.models.load_model("densenet")
|
|
40 |
# load the multi-label classification model
|
41 |
model_multi = tf.keras.models.load_model("densenet")
|
42 |
|
|
|
|
|
|
|
43 |
# define the labels for the multi-label classification model
|
44 |
labels_multi = {0: 'healthy', 1: 'mild', 2: 'moderate'}
|
45 |
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
|
|
40 |
# load the multi-label classification model
|
41 |
model_multi = tf.keras.models.load_model("densenet")
|
42 |
|
43 |
+
# define the labels for the binary classification model
|
44 |
+
labels_binary = {0: 'healthy', 1: 'patient'}
|
45 |
+
|
46 |
# define the labels for the multi-label classification model
|
47 |
labels_multi = {0: 'healthy', 1: 'mild', 2: 'moderate'}
|
48 |
|
49 |
|
50 |
+
# define the function for the binary classification model
|
51 |
+
def classify_binary(inp):
|
52 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
53 |
+
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
54 |
+
prediction = model_binary.predict(inp)
|
55 |
+
confidence = float(prediction[0])
|
56 |
+
label = labels_binary[int(np.round(confidence))]
|
57 |
+
return {label: confidence}
|
58 |
+
|
59 |
+
|
60 |
+
# define the function for the multi-label classification model
|
61 |
+
def classify_multi(inp):
|
62 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
63 |
+
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
64 |
+
prediction = model_multi.predict(inp)
|
65 |
+
confidences = {labels_multi[i]: float(prediction[0][i]) for i in range(3)}
|
66 |
+
return confidences
|
67 |
+
|
68 |
+
|
69 |
+
# create the Gradio interface for the binary classification model
|
70 |
+
binary_interface = gr.Interface(fn=classify_binary,
|
71 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
72 |
+
outputs=gr.outputs.Label(num_top_classes=2),
|
73 |
+
title="Binary Image Classification",
|
74 |
+
description="Classify an image as healthy or patient.",
|
75 |
+
examples=[['300104.png']]
|
76 |
+
)
|
77 |
+
|
78 |
+
# create the Gradio interface for the multi-label classification model
|
79 |
+
multi_interface = gr.Interface(fn=classify_multi,
|
80 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
81 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
82 |
+
title="Multi-class Image Classification",
|
83 |
+
description="Classify an image as healthy, mild or moderate.",
|
84 |
+
examples=[['300104.png']]
|
85 |
+
)
|
86 |
+
|
87 |
+
# create the Gradio app with both interfaces
|
88 |
+
app = gr.Interface([binary_interface, multi_interface], title="Image Classification App")
|
89 |
+
app.launch()
|
90 |
|