|
import streamlit as st |
|
from PIL import Image |
|
import tensorflow as tf |
|
from tensorflow.keras.preprocessing.image import img_to_array |
|
import numpy as np |
|
|
|
path_to_model = "nova.h5" |
|
|
|
model = tf.keras.models.load_model(path_to_model) |
|
|
|
|
|
IMG_HEIGHT = 180 |
|
IMG_WIDTH = 180 |
|
|
|
|
|
def preprocess_image(image): |
|
if image.size != (IMG_HEIGHT, IMG_WIDTH): |
|
image = image.resize((IMG_HEIGHT, IMG_WIDTH)) |
|
|
|
img_array = img_to_array(image) |
|
img_array = img_array / 255.0 |
|
img_array = np.reshape(img_array, (1, IMG_HEIGHT, IMG_WIDTH, 3)) |
|
return img_array |
|
|
|
|
|
|
|
|
|
def main(): |
|
st.title("Nova'23 Classification model") |
|
uploaded_image = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png']) |
|
|
|
|
|
if uploaded_image is not None: |
|
image = Image.open(uploaded_image) |
|
st.image(image, caption='Uploaded Image', use_column_width=True) |
|
|
|
input_image = preprocess_image(image) |
|
prediction = model.predict(input_image) |
|
|
|
|
|
if prediction[0][0] > prediction[0][1]: |
|
st.write('Prediction: Normal') |
|
else: |
|
st.write('Prediction: Pneumonia') |
|
|
|
if __name__ == '__main__': |
|
main() |
|
|