|
|
import streamlit as st |
|
|
from keras.models import load_model |
|
|
from keras.applications.vgg16 import preprocess_input |
|
|
import numpy as np |
|
|
from PIL import Image |
|
|
import tensorflow as tf |
|
|
|
|
|
|
|
|
model = load_model('chest_xray.h5') |
|
|
|
|
|
st.title('Pneumonia Detection from Chest X-Ray Images') |
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("Choose an X-ray image...", type=["jpg", "jpeg", "png"]) |
|
|
|
|
|
def predict(image): |
|
|
|
|
|
img = image.resize((224,224)) |
|
|
x = tf.keras.preprocessing.image.img_to_array(img) |
|
|
x = np.expand_dims(x, axis=0) |
|
|
img_data = preprocess_input(x) |
|
|
|
|
|
|
|
|
classes = model.predict(img_data) |
|
|
return int(classes[0][0]) |
|
|
|
|
|
if uploaded_file is not None: |
|
|
|
|
|
st.image(uploaded_file, caption='Uploaded X-ray Image', use_column_width=True) |
|
|
st.write("") |
|
|
st.write("Classifying...") |
|
|
image = Image.open(uploaded_file) |
|
|
|
|
|
|
|
|
result = predict(image) |
|
|
if result == 0: |
|
|
st.write("Person is Affected By PNEUMONIA") |
|
|
else: |
|
|
st.write("Result is Normal") |