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 # Load your pre-trained model model = load_model('chest_xray.h5') st.title('Pneumonia Detection from Chest X-Ray Images') # Create a file uploader to upload images uploaded_file = st.file_uploader("Choose an X-ray image...", type=["jpg", "jpeg", "png"]) def predict(image): # Preprocess the image to get it into the right format for the model 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) # Make the prediction classes = model.predict(img_data) return int(classes[0][0]) if uploaded_file is not None: # Display the uploaded image st.image(uploaded_file, caption='Uploaded X-ray Image', use_column_width=True) st.write("") st.write("Classifying...") image = Image.open(uploaded_file) # Predict and display the results result = predict(image) if result == 0: st.write("Person is Affected By PNEUMONIA") else: st.write("Result is Normal")