Elena
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,20 +3,16 @@ from tensorflow.keras.models import load_model
|
|
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 |
-
|
20 |
css = """
|
21 |
.gradio-container {
|
22 |
background-color: #f5f5f5;
|
@@ -54,6 +50,7 @@ css = """
|
|
54 |
text-align: center;
|
55 |
}
|
56 |
"""
|
|
|
57 |
description = """
|
58 |
**Automated Pneumonia Detection via Chest X-ray Classification**
|
59 |
|
@@ -66,7 +63,7 @@ This model leverages deep learning techniques to classify chest X-ray images as
|
|
66 |
- Flask and Gradio for deployment and user interaction
|
67 |
|
68 |
**Sample Images:**
|
69 |
-
To test the model, select one of the sample images provided below. Click on an image and then press the "
|
70 |
"""
|
71 |
|
72 |
examples = [
|
@@ -74,7 +71,6 @@ examples = [
|
|
74 |
["samples/pneumonia_xray1.png"],
|
75 |
]
|
76 |
|
77 |
-
# Gradio interface set up instructions
|
78 |
with gr.Blocks(css=css) as interface:
|
79 |
gr.Markdown("<h1>Automated Pneumonia Detection via Chest X-ray Classification</h1>")
|
80 |
gr.Markdown("<p>Upload an X-ray image to detect pneumonia.</p>")
|
@@ -86,7 +82,8 @@ with gr.Blocks(css=css) as interface:
|
|
86 |
submit_btn = gr.Button("Initiate Diagnostic Analysis", elem_classes=["gr-button"])
|
87 |
submit_btn.click(fn=predict, inputs=image_input, outputs=output)
|
88 |
|
89 |
-
|
90 |
gr.Examples(examples=examples, inputs=image_input)
|
|
|
|
|
91 |
|
92 |
interface.launch()
|
|
|
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 |
prediction = model.predict(img_array)
|
13 |
predicted_class = 'Pneumonia' if prediction > 0.5 else 'Normal'
|
14 |
return predicted_class
|
15 |
|
|
|
16 |
css = """
|
17 |
.gradio-container {
|
18 |
background-color: #f5f5f5;
|
|
|
50 |
text-align: center;
|
51 |
}
|
52 |
"""
|
53 |
+
|
54 |
description = """
|
55 |
**Automated Pneumonia Detection via Chest X-ray Classification**
|
56 |
|
|
|
63 |
- Flask and Gradio for deployment and user interaction
|
64 |
|
65 |
**Sample Images:**
|
66 |
+
To test the model, select one of the sample images provided below. Click on an image and then press the "Initiate Diagnostic Analysis" button to receive the results.
|
67 |
"""
|
68 |
|
69 |
examples = [
|
|
|
71 |
["samples/pneumonia_xray1.png"],
|
72 |
]
|
73 |
|
|
|
74 |
with gr.Blocks(css=css) as interface:
|
75 |
gr.Markdown("<h1>Automated Pneumonia Detection via Chest X-ray Classification</h1>")
|
76 |
gr.Markdown("<p>Upload an X-ray image to detect pneumonia.</p>")
|
|
|
82 |
submit_btn = gr.Button("Initiate Diagnostic Analysis", elem_classes=["gr-button"])
|
83 |
submit_btn.click(fn=predict, inputs=image_input, outputs=output)
|
84 |
|
|
|
85 |
gr.Examples(examples=examples, inputs=image_input)
|
86 |
+
|
87 |
+
gr.Markdown(description)
|
88 |
|
89 |
interface.launch()
|