ahmedxeno commited on
Commit
6f2a79e
·
1 Parent(s): 2b40db5

Update app .py

Browse files
Files changed (1) hide show
  1. app .py +31 -24
app .py CHANGED
@@ -1,36 +1,43 @@
1
 
2
  import gradio as gr
3
- import tensorflow as tf
4
- import tensorflow.keras
5
  import matplotlib.pyplot as plt
6
  import cv2
7
- import tensorflow_io as tfio
 
8
  import numpy as np
9
 
10
- loaded_model = tf.keras.models.load_model( 'brain1.h5')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- def take_img(img):
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
- image = gr.inputs.Image(shape=(128,128))
 
34
 
35
  label = gr.outputs.Label('ok')
36
- gr.Interface(fn=take_img, inputs=image, outputs="label",interpretation='default').launch(debug='True')
 
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')