import streamlit as st from tensorflow.keras.models import load_model from PIL import Image import cv2 import numpy as np def resize_image(image): ''' Function to resize an image into 128 * 128 ''' resized_image = cv2.resize(image, (128, 128), interpolation=cv2.INTER_AREA) return resized_image def predict(image): # Loading model model = load_model('InceptionV3.h5') # Resize image into 128x128 resized_image = resize_image(image) # Convert into numpy array image_array = np.array(resized_image) # Rescale image (0-1) rescaled_image = image_array.astype(np.float32) / 255.0 # Expanding dimensions input_image = np.expand_dims(rescaled_image, axis=0) # Make prediction pred = model.predict(input_image) # Convert the prediction to a label if pred[0] > 0.5: label = 'Parasitized Cell' else: label = 'Uninfected Cell' return label def main(): st.title("Malaria Disease Detection") st.write("Upload an image of a cell, and we will predict if it is parasitized or uninfected.") # File uploader uploaded_file = st.file_uploader("Choose an image...", type=['jpg', 'jpeg', 'png']) if uploaded_file is not None: # Read image image = Image.open(uploaded_file) # Convert PIL Image to numpy array image_array = np.array(image) # Make prediction prediction = predict(image_array) prediction = "

Prediction: " + prediction + "

" st.write(prediction, unsafe_allow_html=True) if __name__ == '__main__': main()