CoolFace
Apppublic

AI-Manith/vgg

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
app.py39 linesDownload Raw Back to root
1import streamlit as st2from keras.models import load_model3from keras.applications.vgg16 import preprocess_input4import numpy as np5from PIL import Image6import tensorflow as tf7 8# Load your pre-trained model9model = load_model('chest_xray.h5')10 11st.title('Pneumonia Detection from Chest X-Ray Images')12 13# Create a file uploader to upload images14uploaded_file = st.file_uploader("Choose an X-ray image...", type=["jpg", "jpeg", "png"])15 16def predict(image):17    # Preprocess the image to get it into the right format for the model18    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 prediction24    classes = model.predict(img_data)25    return int(classes[0][0])26 27if uploaded_file is not None:28    # Display the uploaded image29    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 results35    result = predict(image)36    if result == 0:37        st.write("Person is Affected By PNEUMONIA")38    else:39        st.write("Result is Normal")