Abdelrhman-Elruby commited on
Commit
aacc039
1 Parent(s): bceb318

Added main.py

Browse files
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ 2class_98.0.h5
15class_99.8.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c2766c6c89e510b22653077e844530f15a61adffc2801a1a7b84135be4250664
3
+ size 121419384
17class_98.1.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3b0ee74f9ed304d6c528717e7fd2b1385a6df761b2d3a79d7c1a665b2a68df48
3
+ size 121425528
2calss_lagre_dataset_99.1.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:70801ee2d35a41c8de8385b525d676294598239554d255e492f8ac0323a7f8ce
3
+ size 121378648
44class_96.5.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:050a428ad49f450b0baa6a7bf6689e61d6877af23289dfd7dfb816ca8e4b7b54
3
+ size 117140352
alzheimer_99.5.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:278c4b20e67ce5bc2235c389b6bc96b6ab2708e087ff91114743fbbcc88b29e8
3
+ size 117136616
main.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_option_menu import option_menu
3
+ import streamlit.components.v1 as components
4
+ from tensorflow import keras
5
+ import tensorflow as tf
6
+ import numpy as np
7
+ import cv2
8
+ import io
9
+ import pandas as pd
10
+ import os
11
+ os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
12
+
13
+ if 'model' not in st.session_state:
14
+ st.session_state.model = 'Brain Tumor Detection'
15
+ def update_radio():
16
+ st.session_state.model =st.session_state.radio
17
+
18
+ if 'clas' not in st.session_state:
19
+ st.session_state.clas = '2 Classes'
20
+ def update_selbox():
21
+ st.session_state.clas =st.session_state.box
22
+
23
+ if 'check' not in st.session_state:
24
+ st.session_state.check1 = False
25
+ def update_check():
26
+ st.session_state.check1 =st.session_state.check
27
+
28
+ def update_photo():
29
+ st.session_state.photo =st.session_state.image
30
+
31
+ def pred(img,radio,selbox,check):
32
+ img = tf.keras.utils.load_img(
33
+ img,
34
+ grayscale=False,
35
+ color_mode='rgb',
36
+ target_size=(224,224),
37
+ interpolation='nearest',
38
+ keep_aspect_ratio=False
39
+ )
40
+ os.remove(st.session_state.image.name)
41
+ img = np.array(img).reshape(-1, 224, 224, 3)
42
+ if radio =='Alzheimer Detection':
43
+ model = keras.models.load_model('alzheimer_99.5.h5')
44
+ result=['Mild_Demented', 'Moderate_Demented', 'Non_Demented', 'Very_Mild_Demented']
45
+ else:
46
+ if selbox == '44 Classes':
47
+ model = keras.models.load_model('44class_96.5.h5')
48
+ result=['Astrocitoma T1','Astrocitoma T1C+','Astrocitoma T2','Carcinoma T1','Carcinoma T1C+','Carcinoma T2','Ependimoma T1','Ependimoma T1C+','Ependimoma T2','Ganglioglioma T1','Ganglioglioma T1C+',
49
+ 'Ganglioglioma T2','Germinoma T1','Germinoma T1C+','Germinoma T2','Glioblastoma T1','Glioblastoma T1C+','Glioblastoma T2','Granuloma T1','Granuloma T1C+','Granuloma T2','Meduloblastoma T1',
50
+ 'Meduloblastoma T1C+','Meduloblastoma T2','Meningioma T1','Meningioma T1C+','Meningioma T2','Neurocitoma T1','Neurocitoma T1C+','Neurocitoma T2','Oligodendroglioma T1','Oligodendroglioma T1C+',
51
+ 'Oligodendroglioma T2','Papiloma T1','Papiloma T1C+','Papiloma T2','Schwannoma T1','Schwannoma T1C+','Schwannoma T2','Tuberculoma T1','Tuberculoma T1C+','Tuberculoma T2','_NORMAL T1','_NORMAL T2']
52
+ if selbox == '17 Classes':
53
+ model = keras.models.load_model('17class_98.1.h5')
54
+ result=['Glioma (Astrocitoma, Ganglioglioma, Glioblastoma, Oligodendroglioma, Ependimoma) T1','Glioma (Astrocitoma, Ganglioglioma, Glioblastoma, Oligodendroglioma, Ependimoma) T1C+','Glioma (Astrocitoma, Ganglioglioma, Glioblastoma, Oligodendroglioma, Ependimoma) T2',
55
+ 'Meningioma (de Baixo Grau, Atípico, Anaplásico, Transicional) T1','Meningioma (de Baixo Grau, Atípico, Anaplásico, Transicional) T1C+','Meningioma (de Baixo Grau, Atípico, Anaplásico, Transicional) T2','NORMAL T1','NORMAL T2','Neurocitoma (Central - Intraventricular, Extraventricular) T1','Neurocitoma (Central - Intraventricular, Extraventricular) T1C+',
56
+ 'Neurocitoma (Central - Intraventricular, Extraventricular) T2','Outros Tipos de Lesões (Abscessos, Cistos, Encefalopatias Diversas) T1','Outros Tipos de Lesões (Abscessos, Cistos, Encefalopatias Diversas) T1C+','Outros Tipos de Lesões (Abscessos, Cistos, Encefalopatias Diversas) T2','Schwannoma (Acustico, Vestibular - Trigeminal) T1',
57
+ 'Schwannoma (Acustico, Vestibular - Trigeminal) T1C+','Schwannoma (Acustico, Vestibular - Trigeminal) T2']
58
+ if selbox == '15 Classes':
59
+ model = keras.models.load_model('15class_99.8.h5')
60
+ result=['Astrocitoma','Carcinoma','Ependimoma','Ganglioglioma','Germinoma','Glioblastoma','Granuloma','Meduloblastoma','Meningioma','Neurocitoma','Oligodendroglioma','Papiloma','Schwannoma','Tuberculoma','_NORMAL']
61
+ if selbox == '2 Classes':
62
+ model = keras.models.load_model('2calss_lagre_dataset_99.1.h5')
63
+ result=['no', 'yes']
64
+ pred= model.predict(img)
65
+ if check:
66
+ pred=pd.DataFrame({
67
+ 'class_name' : result,
68
+ 'pred_score' : pred.flatten()
69
+ })
70
+ return pred
71
+ pred = np.argmax(pred, axis=1)
72
+ return result[pred[0]]
73
+
74
+ def spr_sidebar():
75
+ menu=option_menu(
76
+ menu_title=None,
77
+ options=['Home','About'],
78
+ icons=['house','info-square'],
79
+ menu_icon='cast',
80
+ default_index=0,
81
+ orientation='horizontal'
82
+ )
83
+ if menu=='Home':
84
+ st.session_state.app_mode = 'Home'
85
+ elif menu=='About':
86
+ st.session_state.app_mode = 'About'
87
+
88
+ def home_page():
89
+ st.session_state.check=st.session_state.check1
90
+ st.session_state.radio=st.session_state.model
91
+ st.session_state.box=st.session_state.clas
92
+ if 'photo' in st.session_state:
93
+ st.session_state.image=st.session_state.photo
94
+
95
+ st.title('Brain Tumor Detection')
96
+ st.session_state.image=st.file_uploader('Upload MRI Image',accept_multiple_files=False,type=['png', 'jpg','jpeg'],key="upload",on_change=update_photo)
97
+ if st.session_state.image != None:
98
+ st.image(st.session_state.image,width=300)
99
+ radio=st.radio("Model",options=('Brain Tumor Detection','Alzheimer Detection'),key='radio',on_change=update_radio)
100
+ check=st.checkbox('Show Prediction Scores',key='check',on_change=update_check)
101
+ if radio =='Brain Tumor Detection':
102
+ selbox=st.selectbox("choose a number of Classes",options=('44 Classes','17 Classes' ,'15 Classes','2 Classes'),index=0,key='box',on_change=update_selbox)
103
+ else:
104
+ selbox=st.radio("choose a number of Classes",options=(['4 Classes']),index=0,key='box1',on_change=update_selbox)
105
+ state =st.button('Get Result')
106
+ if state:
107
+ f=open(st.session_state.image.name, 'wb')
108
+ f.write(st.session_state.image.getbuffer())
109
+ f.close()
110
+
111
+ st.write(pred(st.session_state.image.name,radio,selbox,check))
112
+
113
+
114
+
115
+ def About_page():
116
+ st.write("Soon")
117
+
118
+ def main():
119
+ spr_sidebar()
120
+ if st.session_state.app_mode == 'Home':
121
+ home_page()
122
+ if st.session_state.app_mode == 'About' :
123
+ About_page()
124
+ # Run main()
125
+ if __name__ == '__main__':
126
+ main()