import os import tempfile import numpy as np import streamlit as st import tensorflow as tf from PIL import Image from tensorflow.keras.preprocessing.image import load_img, img_to_array st.title("Nova'23 Classification Model Playground!") st.write("Upload the x-ray image") uploaded_file = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png']) if uploaded_file is not None: # Write the uploaded image data to a temporary file with tempfile.NamedTemporaryFile(delete=False) as f: f.write(uploaded_file.read()) # Get the path of the temporary file img_path = f.name # Display the uploaded image image = Image.open(uploaded_file) st.image(image, caption='Uploaded Image', use_column_width=True) # Load and preprocess the image height = 180 width = 180 channels = 3 img = load_img(img_path, target_size=(height, width)) img_array = img_to_array(img) img_array = img_array / 255.0 img_array = tf.reshape(img_array, [1, height, width, channels]) model = tf.keras.models.load_model('nova.h5') # Make a prediction prediction = model.predict(img_array) if prediction[0][0] > 0.5: print("Prediction: Pneumonia") st.write("Prediction: Pneumonia") else: print("Prediction: Normal") st.write("Prediction: Normal") os.remove(img_path)