pneumonia / app.py
HsbYldz's picture
Upload 3 files
e73b752 verified
import streamlit as st
from tensorflow.keras.models import load_model
from PIL import Image, ImageOps
from PIL import Image
import numpy as np
model=load_model('pneumonia.h5')
# def process_image(img):
# img=img.resize((50,50)) #boyutunu 50 x 50 pixel yaptik
# img=np.array(img)
# img=img/255.0 #normalize ettik
# img=np.expand_dims(img,axis=0)
# return img
def process_image(img):
# Resize the image while maintaining the aspect ratio
img = ImageOps.fit(img, (50, 50), Image.BICUBIC, centering=(0.5, 0.5))
# Convert the image to a numpy array and add the channel dimension if needed
img = np.array(img)
if img.ndim == 2:
img = np.expand_dims(img, axis=-1)
img = np.repeat(img, 3, axis=-1)
elif img.ndim == 3 and img.shape[-1] == 1:
img = np.repeat(img, 3, axis=-1)
# Normalize the pixel values
img = img / 255.0
# Add the batch dimension
img = np.expand_dims(img, axis=0)
return img
st.title("Pnömoni tespiti :lungs:")
st.write("Pnömoni olup olmadığını öğrenmek için röntgen filmi resmini yükle")
file=st.file_uploader('Bir Resim Sec',type=['jpg','jpeg','png'])
if file is not None:
img=Image.open(file)
st.image(img,caption='yuklenen resim')
image= process_image(img)
prediction=model.predict(image)
predicted_class=np.argmax(prediction)
class_names=['normal','pneumonia']
st.write(class_names[predicted_class])