Nova23 / app.py
Akshay-Vs's picture
Update app.py
bfd7638
raw
history blame
1.78 kB
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"
# Load the trained model
model = tf.keras.models.load_model(path_to_model)
# Set the default height and width of the uploaded image
IMG_HEIGHT = 180
IMG_WIDTH = 180
# Define a function to preprocess the image
def preprocess_image(image):
# Resize the image to the expected input size of the model
img = image.resize((IMG_HEIGHT, IMG_WIDTH))
# Convert the image to a numpy array
img_array = img_to_array(img)
# Normalize the pixel values
img_array = img_array / 255.0
# Reshape the image array to match the input shape of the model
img_array = np.reshape(img_array, (1, IMG_HEIGHT, IMG_WIDTH, 3))
return img_array
# Create the Streamlit app
def main():
# Set the title and a brief description
st.title("Nova'23 Classification model")
# Add an image upload option
uploaded_image = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png'])
# If an image has been uploaded, display it and make a prediction
if uploaded_image is not None:
# Display the uploaded image
image = Image.open(uploaded_image)
st.image(image, caption='Uploaded Image', use_column_width=True)
# Preprocess the image for the model
input_image = preprocess_image(image)
# Make a prediction using the model
prediction = model.predict(input_image)
# Display the prediction
if prediction[0][0] > prediction[0][1]:
st.write('Prediction: Normal')
else:
st.write('Prediction: Pneumonia')
if __name__ == '__main__':
main()