File size: 2,071 Bytes
57c47af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76


import io
import numpy as np
from PIL import Image
import streamlit as st
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow import keras


st.title('Brain \U0001F9E0 Tumor Detector ')

st.subheader('Find out whether there is a tumor \U0001F534 (Glioma Meningioma Pituarie) in the brain (or) \
         not \U0001F7E2')




inp_t = st.file_uploader(label='Upload MRI here', accept_multiple_files=True)



def load_img(path):
        # reading file object and making it to pil image and to np array
        img_l = []
        for i in path:
                img_byte = i.read()
                img = Image.open(io.BytesIO(img_byte))
                img = img.resize((64, 64), Image.ANTIALIAS)
                if img.mode != 'L':
                        img = img.convert('L')
                img_arr = np.array(img, dtype='float32')/255
                img_arr = np.expand_dims(img_arr, axis=-1)
                img_l.append(img_arr)
        img = np.stack(img_l)
        return img

# prediction


def pred(img):
    # Load TFLite model and allocate tensors.
    model = keras.models.load_model('model2_weights.h5')
    result = model.predict(img)

    return result



# if file is uploaded
if inp_t:
        img = load_img(inp_t)
        result = ['Glioma', 'Meningioma', 'no tumor', 'Pituarie']

        st.warning(
            '** Uploaded {} images [View images in side Panel]'.format(img.shape[0]))

        res = pred(img)
        max_value = res[0][np.argmax(res)]*100
        if (result[np.argmax(res)] == 'no tumor'):
            st.subheader("\U0001F7E2 Model predicts there is {}  tumor with {:.2f} % confidence].\U0001F7E2".format(result[np.argmax(res)], max_value))
        else:
            st.subheader("\U0001F534  Model predicts there is {}  tumor with {:.2f} % confidence.\U0001F534 ".format(result[np.argmax(res)], max_value))


        st.write('\n')

        st.image(inp_t, width = 400)

   
        st.markdown('---')
        st.error(
            'Dont conclude by looking at predictions, just take them as a reference!!')