Manith Marapperuma
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,39 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
| 3 |
-
from
|
| 4 |
-
from tensorflow.keras.applications.vgg16 import preprocess_input # Import preprocessing function
|
| 5 |
import numpy as np
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
return load_model('chest_xray.h5') # Assuming the model is saved as 'chest_xray.h5'
|
| 10 |
|
| 11 |
-
|
| 12 |
-
model = st.cache(load_model, allow_output_mutation=True)()
|
| 13 |
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
if uploaded_file is not None:
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
if result == 0:
|
| 28 |
-
st.write("
|
| 29 |
else:
|
| 30 |
-
st.write("
|
| 31 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from keras.models import load_model
|
| 3 |
+
from keras.applications.vgg16 import preprocess_input
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import tensorflow as tf
|
| 7 |
|
| 8 |
+
# Load your pre-trained model
|
| 9 |
+
model = load_model('chest_xray.h5')
|
|
|
|
| 10 |
|
| 11 |
+
st.title('Pneumonia Detection from Chest X-Ray Images')
|
|
|
|
| 12 |
|
| 13 |
+
# Create a file uploader to upload images
|
| 14 |
+
uploaded_file = st.file_uploader("Choose an X-ray image...", type=["jpg", "jpeg", "png"])
|
| 15 |
|
| 16 |
+
def predict(image):
|
| 17 |
+
# Preprocess the image to get it into the right format for the model
|
| 18 |
+
img = image.resize((224,224))
|
| 19 |
+
x = tf.keras.preprocessing.image.img_to_array(img)
|
| 20 |
+
x = np.expand_dims(x, axis=0)
|
| 21 |
+
img_data = preprocess_input(x)
|
| 22 |
+
|
| 23 |
+
# Make the prediction
|
| 24 |
+
classes = model.predict(img_data)
|
| 25 |
+
return int(classes[0][0])
|
| 26 |
|
| 27 |
if uploaded_file is not None:
|
| 28 |
+
# Display the uploaded image
|
| 29 |
+
st.image(uploaded_file, caption='Uploaded X-ray Image', use_column_width=True)
|
| 30 |
+
st.write("")
|
| 31 |
+
st.write("Classifying...")
|
| 32 |
+
image = Image.open(uploaded_file)
|
| 33 |
+
|
| 34 |
+
# Predict and display the results
|
| 35 |
+
result = predict(image)
|
| 36 |
if result == 0:
|
| 37 |
+
st.write("Person is Affected By PNEUMONIA")
|
| 38 |
else:
|
| 39 |
+
st.write("Result is Normal")
|
|
|