File size: 1,777 Bytes
6a18290 f612bb0 6a18290 bfd7638 6a18290 |
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
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()
|