File size: 2,242 Bytes
f2df012
6d30216
 
 
 
c64895a
6d30216
 
0027a76
63f6424
6d30216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5dc78d
6d30216
 
 
f2df012
6d30216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5dc78d
6d30216
 
 
 
 
 
 
 
 
 
 
 
 
f2df012
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
62
63
64
65
66
67
68
69
# import all necessary libraries
import streamlit as st
from tensorflow.keras.models import load_model
from PIL import Image
import numpy as np
import tensorflow as tf

# load the models
model1 = load_model('Model_From_VGG16.h5')
model2 = load_model('Model_basic_From_Scratch.h5')

# define a function to predict using model 1
def predict_model1(image):
    # preprocess the image
    img = np.array(image.convert('RGB').resize((64, 64))) / 255.0
    img = np.expand_dims(img, axis=0)

    # make a prediction using model 1
    prediction = model1.predict(img)
    return prediction

# define a function to predict using model 2
def predict_model2(image):
    # preprocess the image
    img = np.array(image.convert('RGB').resize((128, 128))) / 255.0
    img = np.expand_dims(img, axis=0)

    # make a prediction using model 2
    prediction = model2.predict(img)
    return prediction

# create the Streamlit app
def app():
    st.title('Malaria Parasite Presence Detector Using Not One But Two Models')
    st.write('Upload an image and see the predictions of two CNN models!')

    # create file uploader
    uploaded_file = st.file_uploader("Upload Magnified Blood Samples Only!", type=["jpg", "jpeg", "png"])

    # check if file has been uploaded
    if uploaded_file is not None:
        # load the image
        image = Image.open(uploaded_file)

        # display the image
        st.image(image, caption='Uploaded Image', use_column_width=True)

        # make a prediction using model 1
        prediction1 = predict_model1(image)

        # make a prediction using model 2
        prediction2 = predict_model2(image)

        # display the predictions
        st.subheader('Model 1 Prediction - Transfer Learning_VGG16')
        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')
        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")

# run the app
if __name__ == '__main__':
    app()