Spaces:
Runtime error
Runtime error
Update app .py
Browse files
app .py
CHANGED
@@ -1,36 +1,43 @@
|
|
1 |
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
import tensorflow.keras
|
5 |
import matplotlib.pyplot as plt
|
6 |
import cv2
|
7 |
-
import
|
|
|
8 |
import numpy as np
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
resize = tf.image.resize(img, (128,128))
|
15 |
-
gray = tfio.experimental.color.bgr_to_rgb(resize)
|
16 |
-
yhat = loaded_model.predict(np.expand_dims(gray/255, 0))
|
17 |
-
label_names = {
|
18 |
-
"1": "Tumor",
|
19 |
-
"2": "Normal"}
|
20 |
-
classes_x=np.argmax(yhat,axis=1)
|
21 |
-
a = classes_x[0]
|
22 |
-
input_value = a + 1
|
23 |
-
input_str = str(input_value)
|
24 |
-
predicted_label = label_names[input_str]
|
25 |
-
tumor = yhat[0][0]
|
26 |
-
tumor = str(tumor)
|
27 |
-
normal = yhat[0][1]
|
28 |
-
normal = str(normal)
|
29 |
-
return {'Tumour': tumor, 'Normal':normal}
|
30 |
|
|
|
|
|
|
|
31 |
|
|
|
32 |
|
33 |
-
|
|
|
34 |
|
35 |
label = gr.outputs.Label('ok')
|
36 |
-
gr.Interface(fn=
|
|
|
1 |
|
2 |
import gradio as gr
|
3 |
+
|
|
|
4 |
import matplotlib.pyplot as plt
|
5 |
import cv2
|
6 |
+
import torch
|
7 |
+
import timm
|
8 |
import numpy as np
|
9 |
|
10 |
+
midas = torch.hub.load('intel-isl/MiDaS', 'MiDaS_small')
|
11 |
+
midas.to('cpu')
|
12 |
+
midas.eval()
|
13 |
+
|
14 |
+
transforms = torch.hub.load('intel-isl/MiDaS', 'transforms')
|
15 |
+
transform = transforms.small_transform
|
16 |
+
|
17 |
+
def predict_image(img):
|
18 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
19 |
+
|
20 |
+
input_batch = transform(img).to('cpu')
|
21 |
+
with torch.no_grad():
|
22 |
+
prediction = midas(input_batch)
|
23 |
+
|
24 |
+
prediction = torch.nn.functional.interpolate(
|
25 |
+
prediction.unsqueeze(1),
|
26 |
+
size=img.shape[:2],
|
27 |
+
mode="bicubic",
|
28 |
+
align_corners=False,
|
29 |
+
).squeeze()
|
30 |
|
31 |
+
img = prediction.cpu().numpy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
img = (img / 1000.0)*255
|
34 |
+
out = (img).astype(np.uint8)
|
35 |
+
|
36 |
|
37 |
+
return out
|
38 |
|
39 |
+
|
40 |
+
image = gr.inputs.Image()
|
41 |
|
42 |
label = gr.outputs.Label('ok')
|
43 |
+
gr.Interface(fn=predict_image, inputs=image, outputs=image).launch(debug='True')
|