File size: 1,208 Bytes
a8de88e
9b67c0d
 
f076585
9b67c0d
 
f076585
9b67c0d
 
f076585
9b67c0d
f076585
9b67c0d
 
f076585
9b67c0d
 
 
 
 
 
 
 
 
 
f076585
a8de88e
9b67c0d
 
 
 
 
 
 
 
a8de88e
9b67c0d
a8de88e
9b67c0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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")