Update app.py
Browse files
app.py
CHANGED
|
@@ -2,29 +2,42 @@ import streamlit as st
|
|
| 2 |
import numpy as np
|
| 3 |
import tensorflow as tf
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
import io
|
| 6 |
|
| 7 |
-
# Load
|
| 8 |
model = tf.keras.models.load_model('model.keras')
|
| 9 |
|
| 10 |
# Define the image preprocessing function
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
return image_array
|
| 22 |
|
| 23 |
# Define the class labels
|
| 24 |
class_labels = ['Atelectasis', 'Cardiomegaly', 'Consolidation', 'Edema', 'Effusion',
|
| 25 |
'Emphysema', 'Fibrosis', 'Infiltration', 'Mass',
|
| 26 |
'Nodule', 'Pleural_Thickening', 'Pneumothorax']
|
| 27 |
-
# class_labels = ["Class1", "Class2", "Class3", "Class4", "Class5"] # Update with actual class names
|
| 28 |
|
| 29 |
# Streamlit app
|
| 30 |
st.title("Chest X-ray Classification")
|
|
@@ -54,7 +67,7 @@ if uploaded_file is not None:
|
|
| 54 |
with col2:
|
| 55 |
# Display results
|
| 56 |
if not top_predictions:
|
| 57 |
-
st.write("No
|
| 58 |
else:
|
| 59 |
st.write("Predicted Disease(s):")
|
| 60 |
for label, prob in top_predictions:
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import tensorflow as tf
|
| 4 |
from PIL import Image
|
| 5 |
+
import cv2 as cv
|
| 6 |
import io
|
| 7 |
|
| 8 |
+
# Load trained model
|
| 9 |
model = tf.keras.models.load_model('model.keras')
|
| 10 |
|
| 11 |
# Define the image preprocessing function
|
| 12 |
+
def preprocess_image(image):
|
| 13 |
+
# Convert to numpy array
|
| 14 |
+
image_array = np.array(image)
|
| 15 |
+
|
| 16 |
+
# Apply Gaussian Blur
|
| 17 |
+
image_array = cv.GaussianBlur(image_array, (9, 9), 0)
|
| 18 |
+
|
| 19 |
+
# Apply CLAHE
|
| 20 |
+
clahe = cv.createCLAHE(clipLimit=3, tileGridSize=(10, 10))
|
| 21 |
+
clahe_image = clahe.apply(image_array)
|
| 22 |
+
|
| 23 |
+
# Convert CLAHE image to RGB
|
| 24 |
+
clahe_image = cv.cvtColor(clahe_image, cv.COLOR_GRAY2RGB)
|
| 25 |
+
|
| 26 |
+
# Normalize image to [0, 1]
|
| 27 |
+
clahe_image = (clahe_image - clahe_image.min()) / (clahe_image.max() - clahe_image.min())
|
| 28 |
+
|
| 29 |
+
# Resize the image to 224x224
|
| 30 |
+
image_resized = cv.resize(clahe_image, (224, 224))
|
| 31 |
+
|
| 32 |
+
# Add batch dimension
|
| 33 |
+
image_array = np.expand_dims(image_resized, axis=0).astype(np.float32)
|
| 34 |
+
|
| 35 |
return image_array
|
| 36 |
|
| 37 |
# Define the class labels
|
| 38 |
class_labels = ['Atelectasis', 'Cardiomegaly', 'Consolidation', 'Edema', 'Effusion',
|
| 39 |
'Emphysema', 'Fibrosis', 'Infiltration', 'Mass',
|
| 40 |
'Nodule', 'Pleural_Thickening', 'Pneumothorax']
|
|
|
|
| 41 |
|
| 42 |
# Streamlit app
|
| 43 |
st.title("Chest X-ray Classification")
|
|
|
|
| 67 |
with col2:
|
| 68 |
# Display results
|
| 69 |
if not top_predictions:
|
| 70 |
+
st.write("No diseases found with probability greater than 50%.")
|
| 71 |
else:
|
| 72 |
st.write("Predicted Disease(s):")
|
| 73 |
for label, prob in top_predictions:
|