Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import numpy as np
|
3 |
+
import time
|
4 |
+
import os
|
5 |
+
|
6 |
+
|
7 |
+
from PIL import Image
|
8 |
+
|
9 |
+
|
10 |
+
import gradio as gr
|
11 |
+
|
12 |
+
ch_detection_model1 = cv2.dnn.readNet('tumor_classifier_mixed_datasets.onnx')
|
13 |
+
|
14 |
+
def main_func(im):
|
15 |
+
im=cv2.resize(im,(224,224))
|
16 |
+
im=cv2.cvtColor(im, cv2.COLOR_RGB2BGR)
|
17 |
+
im = (im.astype(np.float32)) / 255.0
|
18 |
+
im=im[np.newaxis, ...]
|
19 |
+
#print(im.shape)
|
20 |
+
ch_detection_model1.setInput(im)
|
21 |
+
|
22 |
+
outputs=ch_detection_model1.forward(ch_detection_model1.getUnconnectedOutLayersNames())
|
23 |
+
outputs=np.array(outputs)
|
24 |
+
outputs=outputs.reshape(-1)
|
25 |
+
if outputs[0]>0.49:
|
26 |
+
results=("predicted as Tumor with probability :"+str(outputs[0]))
|
27 |
+
return results
|
28 |
+
if outputs[0]<0.50:
|
29 |
+
results=("There is No-Tumor with probability :"+str(1-outputs[0]))
|
30 |
+
return results
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
def final_func():
|
35 |
+
gr.Interface(fn=main_func,
|
36 |
+
inputs=gr.Image(),
|
37 |
+
outputs='text').launch()
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
final_func()
|
41 |
+
|
42 |
+
|