|
|
|
import streamlit as st |
|
from tensorflow.keras.models import load_model |
|
from PIL import Image |
|
import numpy as np |
|
import tensorflow as tf |
|
from transformers import AutoModel |
|
|
|
|
|
|
|
|
|
model1 = AutoModel.from_pretrained('kusumakar/Malaria_parasite_presence_detection/Model_From_VGG16.h5') |
|
model2 = AutoModel.from_pretrained('kusumakar/Malaria_parasite_presence_detection/Model_Basic_From_Scratch.h5') |
|
|
|
|
|
def predict_model1(image): |
|
|
|
img = np.array(image.convert('RGB').resize((64, 64))) / 255.0 |
|
img = np.expand_dims(img, axis=0) |
|
|
|
|
|
prediction = model1.predict(img) |
|
|
|
return prediction |
|
|
|
|
|
def predict_model2(image): |
|
|
|
img = np.array(image.convert('RGB').resize((128, 128))) / 255.0 |
|
img = np.expand_dims(img, axis=0) |
|
|
|
|
|
prediction = model2.predict(img) |
|
|
|
return prediction |
|
|
|
|
|
def app(): |
|
st.title('Malaria Detector - CNN Model Comparison') |
|
st.write('Upload an image and see the predictions of two CNN models!') |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload Magnified Blood Samples Only!", type=["jpg", "jpeg", "png"]) |
|
|
|
|
|
if uploaded_file is not None: |
|
|
|
image = Image.open(uploaded_file) |
|
|
|
|
|
st.image(image, caption='Uploaded Image', use_column_width=True) |
|
|
|
|
|
prediction1 = predict_model1(image) |
|
|
|
|
|
prediction2 = predict_model2(image) |
|
|
|
|
|
st.subheader('Model 1 Prediction - Transfer Learning_VGG19') |
|
st.write(prediction1) |
|
if np.argmax(prediction1) == 0: |
|
st.write("Malaria Parasite Not Present in the Blood sample") |
|
else: |
|
st.write("Malaria Parasite Present in the Blood sample") |
|
|
|
|
|
st.subheader('Model 2 Prediction - Built from Scratch') |
|
st.write(prediction2) |
|
if np.round(prediction2) == 1: |
|
st.write("Malaria Parasite Not Present in the Blood sample") |
|
else: |
|
st.write("Malaria Parasite Present in the Blood sample") |
|
|
|
|
|
if __name__ == '__main__': |
|
app() |