Spaces:
Sleeping
Sleeping
File size: 1,632 Bytes
7390777 | 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 56 57 58 59 60 61 | 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 = "<h3 style='font-family: Arial;'>Prediction: " + prediction + "</h3>"
st.write(prediction, unsafe_allow_html=True)
if __name__ == '__main__':
main()
|