vmath commited on
Commit
4a36cf4
·
1 Parent(s): 124f163

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +190 -0
app.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from tensorflow import keras
5
+ import h5py
6
+
7
+ model1 = keras.models.load_model('NormalViralPneumonia.h5')
8
+ model2 = keras.models.load_model('NormalvsBacterialPneumonia.h5')
9
+ model3 = keras.models.load_model('NormalvsEffusion.h5')
10
+ model4 = keras.models.load_model('normalCardiomegaly.h5')
11
+ model5 = keras.models.load_model('normalNodule.h5')
12
+ model6 = keras.models.load_model('normalPleural.h5')
13
+ model7 = keras.models.load_model('normalTuber.h5')
14
+ model8 = keras.models.load_model('normal_covid19.h5')
15
+ model9 = keras.models.load_model('normalvsAtelectasis.h5')
16
+ model10 = keras.models.load_model('normalvsConsolidation.h5')
17
+ model11 = keras.models.load_model('normalvsEmphysema.h5')
18
+ model12 = keras.models.load_model('normalvsInfiltration.h5')
19
+ model13 = keras.models.load_model('normalvsMass.h5')
20
+ model14 = keras.models.load_model('normalvsPnemonia.h5')
21
+ model15 = keras.models.load_model('normalvspneumothorax.h5')
22
+
23
+ class_names = ["Normal", "Viral Pneumonia"]
24
+ def predict_input_image(img):
25
+ img_4d=img.reshape(-1,224,224,3)
26
+ prediction=model1.predict(img_4d)[0]
27
+ return {class_names[i]: float(prediction[i]) for i in range(2)}
28
+
29
+ class_names2 = ["Normal", "Bacterial Pneumonia"]
30
+ def predict_input_image2(img):
31
+ img_4d=img.reshape(-1,224,224,3)
32
+ prediction2=model2.predict(img_4d)[0]
33
+ return {class_names2[i]: float(prediction2[i]) for i in range(2)}
34
+
35
+ class_names3 = ["Normal", "Effusion"]
36
+ def predict_input_image3(img):
37
+ img_4d=img.reshape(-1,224,224,3)
38
+ prediction3=model3.predict(img_4d)[0]
39
+ return {class_names3[i]: float(prediction3[i]) for i in range(2)}
40
+
41
+ class_names4 = ["Normal", "Cardiomegaly"]
42
+ def predict_input_image4(img):
43
+ img_4d=img.reshape(-1,224,224,3)
44
+ prediction4=model4.predict(img_4d)[0]
45
+ return {class_names4[i]: float(prediction4[i]) for i in range(2)}
46
+
47
+ class_names5 = ["Normal", "Nodule"]
48
+ def predict_input_image5(img):
49
+ img_4d=img.reshape(-1,224,224,3)
50
+ prediction5=model5.predict(img_4d)[0]
51
+ return {class_names5[i]: float(prediction5[i]) for i in range(2)}
52
+
53
+ class_names6 = ["Normal", "Pleural"]
54
+ def predict_input_image6(img):
55
+ img_4d=img.reshape(-1,224,224,3)
56
+ prediction6=model6.predict(img_4d)[0]
57
+ return {class_names6[i]: float(prediction6[i]) for i in range(2)}
58
+
59
+ class_names7 = ["Normal", "Tuberculosis"]
60
+ def predict_input_image7(img):
61
+ img_4d=img.reshape(-1,224,224,3)
62
+ prediction7=model7.predict(img_4d)[0]
63
+ return {class_names7[i]: float(prediction7[i]) for i in range(2)}
64
+
65
+ class_names8 = ["Normal", "COVID-19"]
66
+ def predict_input_image8(img):
67
+ img_4d=img.reshape(-1,224,224,3)
68
+ prediction8=model8.predict(img_4d)[0]
69
+ return {class_names8[i]: float(prediction8[i]) for i in range(2)}
70
+
71
+ class_names9 = ["Normal", "Atelectasis"]
72
+ def predict_input_image9(img):
73
+ img_4d=img.reshape(-1,224,224,3)
74
+ prediction9=model9.predict(img_4d)[0]
75
+ return {class_names9[i]: float(prediction9[i]) for i in range(2)}
76
+
77
+ class_names10 = ["Normal", "Consolidation"]
78
+ def predict_input_image10(img):
79
+ img_4d=img.reshape(-1,224,224,3)
80
+ prediction10=model10.predict(img_4d)[0]
81
+ return {class_names10[i]: float(prediction10[i]) for i in range(2)}
82
+
83
+ class_names11 = ["Normal", "Emphysema"]
84
+ def predict_input_image11(img):
85
+ img_4d=img.reshape(-1,224,224,3)
86
+ prediction11=model11.predict(img_4d)[0]
87
+ return {class_names11[i]: float(prediction11[i]) for i in range(2)}
88
+
89
+ class_names12 = ["Normal", "Infiltration"]
90
+ def predict_input_image12(img):
91
+ img_4d=img.reshape(-1,224,224,3)
92
+ prediction12=model12.predict(img_4d)[0]
93
+ return {class_names12[i]: float(prediction12[i]) for i in range(2)}
94
+
95
+ class_names13 = ["Normal", "Mass"]
96
+ def predict_input_image13(img):
97
+ img_4d=img.reshape(-1,224,224,3)
98
+ prediction13=model13.predict(img_4d)[0]
99
+ return {class_names13[i]: float(prediction13[i]) for i in range(2)}
100
+
101
+ class_names14 = ["Normal", "Pneumonia"]
102
+ def predict_input_image14(img):
103
+ img_4d=img.reshape(-1,224,224,3)
104
+ prediction14=model14.predict(img_4d)[0]
105
+ return {class_names14[i]: float(prediction14[i]) for i in range(2)}
106
+
107
+ class_names15 = ["Normal", "Pneumothorax"]
108
+ def predict_input_image15(img):
109
+ img_4d=img.reshape(-1,224,224,3)
110
+ prediction15=model15.predict(img_4d)[0]
111
+ return {class_names15[i]: float(prediction15[i]) for i in range(2)}
112
+
113
+ with gr.Blocks() as iface:
114
+ with gr.Tab("Viral Pneumonia Detection"):
115
+ image1 = gr.inputs.Image(shape=(224,224))
116
+ label1 = gr.outputs.Label(num_top_classes=2)
117
+ m1_button = gr.Button("Submit")
118
+ with gr.Tab("Bacterial Pneumonia Detection"):
119
+ image2 = gr.inputs.Image(shape=(224,224))
120
+ label2 = gr.outputs.Label(num_top_classes=2)
121
+ m2_button = gr.Button("Submit")
122
+ with gr.Tab("Effusion Detection"):
123
+ image3 = gr.inputs.Image(shape=(224,224))
124
+ label3 = gr.outputs.Label(num_top_classes=2)
125
+ m3_button = gr.Button("Submit")
126
+ with gr.Tab("Cardiomegaly Detection"):
127
+ image4 = gr.inputs.Image(shape=(224,224))
128
+ label4 = gr.outputs.Label(num_top_classes=2)
129
+ m4_button = gr.Button("Submit")
130
+ with gr.Tab("Nodule Detection"):
131
+ image5 = gr.inputs.Image(shape=(224,224))
132
+ label5 = gr.outputs.Label(num_top_classes=2)
133
+ m5_button = gr.Button("Submit")
134
+ with gr.Tab("Pleural Detection"):
135
+ image6 = gr.inputs.Image(shape=(224,224))
136
+ label6 = gr.outputs.Label(num_top_classes=2)
137
+ m6_button = gr.Button("Submit")
138
+ with gr.Tab("Tuberculosis Detection"):
139
+ image7 = gr.inputs.Image(shape=(224,224))
140
+ label7 = gr.outputs.Label(num_top_classes=2)
141
+ m7_button = gr.Button("Submit")
142
+ with gr.Tab("COVID-19 Detection"):
143
+ image8 = gr.inputs.Image(shape=(224,224))
144
+ label8 = gr.outputs.Label(num_top_classes=2)
145
+ m8_button = gr.Button("Submit")
146
+ with gr.Tab("Atelectasis Detection"):
147
+ image9 = gr.inputs.Image(shape=(224,224))
148
+ label9 = gr.outputs.Label(num_top_classes=2)
149
+ m9_button = gr.Button("Submit")
150
+ with gr.Tab("Consolidation Detection"):
151
+ image10 = gr.inputs.Image(shape=(224,224))
152
+ label10 = gr.outputs.Label(num_top_classes=2)
153
+ m10_button = gr.Button("Submit")
154
+ with gr.Tab("Emphysema Detection"):
155
+ image11 = gr.inputs.Image(shape=(224,224))
156
+ label11 = gr.outputs.Label(num_top_classes=2)
157
+ m11_button = gr.Button("Submit")
158
+ with gr.Tab("Infiltration Detection"):
159
+ image12 = gr.inputs.Image(shape=(224,224))
160
+ label12 = gr.outputs.Label(num_top_classes=2)
161
+ m12_button = gr.Button("Submit")
162
+ with gr.Tab("Mass Detection"):
163
+ image13 = gr.inputs.Image(shape=(224,224))
164
+ label13 = gr.outputs.Label(num_top_classes=2)
165
+ m13_button = gr.Button("Submit")
166
+ with gr.Tab("Pneumonia Detection"):
167
+ image14 = gr.inputs.Image(shape=(224,224))
168
+ label14 = gr.outputs.Label(num_top_classes=2)
169
+ m14_button = gr.Button("Submit")
170
+ with gr.Tab("Pneumothorax Detection"):
171
+ image15 = gr.inputs.Image(shape=(224,224))
172
+ label15 = gr.outputs.Label(num_top_classes=2)
173
+ m15_button = gr.Button("Submit")
174
+
175
+ m1_button.click(predict_input_image, inputs=image1, outputs=label1)
176
+ m2_button.click(predict_input_image2, inputs=image2, outputs=label2)
177
+ m3_button.click(predict_input_image3, inputs=image3, outputs=label3)
178
+ m4_button.click(predict_input_image4, inputs=image4, outputs=label4)
179
+ m5_button.click(predict_input_image5, inputs=image5, outputs=label5)
180
+ m6_button.click(predict_input_image6, inputs=image6, outputs=label6)
181
+ m7_button.click(predict_input_image7, inputs=image7, outputs=label7)
182
+ m8_button.click(predict_input_image8, inputs=image8, outputs=label8)
183
+ m9_button.click(predict_input_image9, inputs=image9, outputs=label9)
184
+ m10_button.click(predict_input_image10, inputs=image10, outputs=label10)
185
+ m11_button.click(predict_input_image11, inputs=image11, outputs=label11)
186
+ m12_button.click(predict_input_image12, inputs=image12, outputs=label12)
187
+ m13_button.click(predict_input_image13, inputs=image13, outputs=label13)
188
+ m14_button.click(predict_input_image14, inputs=image14, outputs=label14)
189
+ m15_button.click(predict_input_image15, inputs=image15, outputs=label15)
190
+ iface.launch(share=True, auth=("username", "password"))