Elena
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,17 +3,17 @@ from tensorflow.keras.models import load_model
|
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
|
|
|
6 |
model = load_model('xray_image_classifier_model.keras')
|
7 |
|
8 |
def predict(image):
|
|
|
9 |
img = image.resize((150, 150))
|
10 |
img_array = np.array(img) / 255.0
|
11 |
img_array = np.expand_dims(img_array, axis=0)
|
12 |
|
13 |
-
# Make a prediction
|
14 |
prediction = model.predict(img_array)
|
15 |
predicted_class = 'Pneumonia' if prediction > 0.5 else 'Normal'
|
16 |
-
|
17 |
return predicted_class
|
18 |
|
19 |
|
@@ -55,7 +55,13 @@ css = """
|
|
55 |
}
|
56 |
"""
|
57 |
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
with gr.Blocks(css=css) as interface:
|
60 |
gr.Markdown("<h1>Chest X-ray Pneumonia Classifier</h1>")
|
61 |
gr.Markdown("<p>Upload an X-ray image to classify it as 'Pneumonia' or 'Normal'.</p>")
|
@@ -67,4 +73,7 @@ with gr.Blocks(css=css) as interface:
|
|
67 |
submit_btn = gr.Button("Classify X-ray", elem_classes=["gr-button"])
|
68 |
submit_btn.click(fn=predict, inputs=image_input, outputs=output)
|
69 |
|
|
|
|
|
|
|
70 |
interface.launch()
|
|
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
|
6 |
+
|
7 |
model = load_model('xray_image_classifier_model.keras')
|
8 |
|
9 |
def predict(image):
|
10 |
+
|
11 |
img = image.resize((150, 150))
|
12 |
img_array = np.array(img) / 255.0
|
13 |
img_array = np.expand_dims(img_array, axis=0)
|
14 |
|
|
|
15 |
prediction = model.predict(img_array)
|
16 |
predicted_class = 'Pneumonia' if prediction > 0.5 else 'Normal'
|
|
|
17 |
return predicted_class
|
18 |
|
19 |
|
|
|
55 |
}
|
56 |
"""
|
57 |
|
58 |
+
|
59 |
+
examples = [
|
60 |
+
["samples/normal_xray1.jpg"],
|
61 |
+
["samples/pneumonia_xray1.jpg"],
|
62 |
+
]
|
63 |
+
|
64 |
+
# Gradio interface set up instructions
|
65 |
with gr.Blocks(css=css) as interface:
|
66 |
gr.Markdown("<h1>Chest X-ray Pneumonia Classifier</h1>")
|
67 |
gr.Markdown("<p>Upload an X-ray image to classify it as 'Pneumonia' or 'Normal'.</p>")
|
|
|
73 |
submit_btn = gr.Button("Classify X-ray", elem_classes=["gr-button"])
|
74 |
submit_btn.click(fn=predict, inputs=image_input, outputs=output)
|
75 |
|
76 |
+
|
77 |
+
gr.Examples(examples=examples, inputs=image_input)
|
78 |
+
|
79 |
interface.launch()
|