Spaces:
Sleeping
Sleeping
updating
Browse files
app.py
CHANGED
@@ -36,43 +36,38 @@ labels_cnn = {0: 'healthy', 1: 'patient'}
|
|
36 |
labels_efficientnet = {0: 'healthy', 1: 'patient'}
|
37 |
|
38 |
def classify_cnn(inp):
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
prediction = model_cnn.predict(img)
|
43 |
confidence = float(prediction[0])
|
44 |
return {labels_cnn[prediction.argmax()]: confidence}
|
45 |
|
46 |
def classify_efficientnet(inp):
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
prediction = model_efficientnet.predict(img)
|
51 |
confidence = float(prediction[0])
|
52 |
return {labels_efficientnet[prediction.argmax()]: confidence}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
)
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
examples=[['300104.png']]
|
68 |
-
)
|
69 |
-
# create a combined interface with tabs for each binary classification model
|
70 |
-
demo = gr.Interface([cnn_interface, efficientnet_interface],
|
71 |
-
"tab",
|
72 |
-
title="Binary Image Classification",
|
73 |
-
description="Classify an image as healthy or patient using different binary classification models."
|
74 |
-
)
|
75 |
-
|
76 |
-
demo.launch()
|
77 |
-
|
78 |
|
|
|
|
36 |
labels_efficientnet = {0: 'healthy', 1: 'patient'}
|
37 |
|
38 |
def classify_cnn(inp):
|
39 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
40 |
+
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
41 |
+
prediction = model_cnn.predict(inp)
|
|
|
42 |
confidence = float(prediction[0])
|
43 |
return {labels_cnn[prediction.argmax()]: confidence}
|
44 |
|
45 |
def classify_efficientnet(inp):
|
46 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
47 |
+
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
48 |
+
prediction = model_efficientnet.predict(inp)
|
|
|
49 |
confidence = float(prediction[0])
|
50 |
return {labels_efficientnet[prediction.argmax()]: confidence}
|
51 |
+
|
52 |
+
# Create the Gradio interfaces for each binary classification model
|
53 |
+
cnn_binary_interface = gr.Interface(fn=classify_cnn,
|
54 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
55 |
+
outputs=gr.outputs.Label(num_top_classes=2),
|
56 |
+
title="CNN Binary Image Classification",
|
57 |
+
description="Classify an image as healthy or patient using a CNN model.",
|
58 |
+
examples=[['300104.png']])
|
59 |
|
60 |
+
efficientnet_binary_interface = gr.Interface(fn=classify_efficientnet,
|
61 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
62 |
+
outputs=gr.outputs.Label(num_top_classes=2),
|
63 |
+
title="EfficientNet Binary Image Classification",
|
64 |
+
description="Classify an image as healthy or patient using an EfficientNet model.",
|
65 |
+
examples=[['300104.png']])
|
|
|
66 |
|
67 |
+
# Create the Gradio demo that allows the user to choose between the two binary classification models
|
68 |
+
binary_demo = gr.Interface([cnn_binary_interface, efficientnet_binary_interface],
|
69 |
+
"tabs",
|
70 |
+
title="Binary Image Classification",
|
71 |
+
description="Classify an image as healthy or patient using one of two binary classification models.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
binary_demo.launch()
|