Spaces:
Sleeping
Sleeping
two_interface
Browse files
app.py
CHANGED
@@ -33,58 +33,37 @@ from transformers import pipeline
|
|
33 |
#labels = ['Healthy', 'Patient']
|
34 |
#labels = {0: 'healthy', 1: 'patient'}
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
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 |
-
# 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 |
|
|
|
33 |
#labels = ['Healthy', 'Patient']
|
34 |
#labels = {0: 'healthy', 1: 'patient'}
|
35 |
|
36 |
+
# Load the model
|
37 |
+
model = tf.keras.models.load_model("densenet")
|
38 |
+
|
39 |
+
# Define the labels
|
40 |
+
labels = {0: 'healthy', 1: 'patient'}
|
41 |
+
|
42 |
+
def classify_image(inp):
|
43 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
44 |
+
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
45 |
+
prediction = model.predict(inp)
|
46 |
+
confidences = {labels[i]: float(prediction[0][i]) for i in range(2)}
|
47 |
+
return confidences
|
48 |
+
|
49 |
+
# Create the binary interface
|
50 |
+
binary_interface = gr.Interface(fn=classify_image,
|
51 |
+
inputs=gr.Image(shape=(224, 224)),
|
52 |
+
outputs=gr.Label(num_top_classes=2),
|
53 |
+
title="Binary Image Classification",
|
54 |
+
description="Classify an image as healthy or patient.",
|
55 |
+
examples=[['300104.png']]
|
56 |
+
)
|
57 |
+
|
58 |
+
# Create the multi-class interface
|
59 |
+
multi_interface = gr.Interface(fn=classify_image,
|
60 |
+
inputs=gr.Image(shape=(224, 224)),
|
61 |
+
outputs=gr.Label(num_top_classes=3),
|
62 |
+
title="Multi-class Image Classification",
|
63 |
+
description="Classify an image as healthy, mild or moderate.",
|
64 |
+
examples=[['300104.png']]
|
65 |
+
)
|
66 |
+
|
67 |
+
# Launch the app
|
68 |
+
gr.Interface([binary_interface, multi_interface], "grid", title="My Image Classification App").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|