yuragoithf commited on
Commit
4e2e389
·
1 Parent(s): 7a03b44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
  import gdown
 
4
  from PIL import Image
5
 
6
  import os
@@ -14,6 +15,9 @@ import keras.backend as K
14
  resized_shape = (768, 768, 3)
15
  IMG_SCALING = (1, 1)
16
 
 
 
 
17
 
18
  # Download the model file
19
  def download_model():
@@ -49,15 +53,11 @@ def dice_coef(y_true, y_pred, smooth=1):
49
  seg_model = tf.keras.models.load_model('seg_unet_model.h5', custom_objects={'Combo_loss': Combo_loss, 'dice_coef': dice_coef})
50
 
51
  inputs = gr.inputs.Image(type="pil", label="Upload an image", source="upload")
 
52
  image_output = gr.outputs.Image(type="pil", label="Output Image")
53
  # outputs = gr.outputs.HTML() #uncomment for single class output
54
 
55
  def gen_pred(img=inputs, model=seg_model):
56
-
57
- img = cv2.imread('./003e2c95d.jpg')
58
- path = os.getcwd()
59
- tmp = os.listdir(path)
60
- print(tmp)
61
  #rgb_path = os.path.join(test_image_dir,img)
62
  #img = cv2.imread(rgb_path)
63
  img = img[::IMG_SCALING[0], ::IMG_SCALING[1]]
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import gdown
4
+ import urllib.request
5
  from PIL import Image
6
 
7
  import os
 
15
  resized_shape = (768, 768, 3)
16
  IMG_SCALING = (1, 1)
17
 
18
+ def get_opencv_img_from_buffer(buffer, flags=cv2.IMREAD_COLOR):
19
+ bytes_as_np_array = np.frombuffer(buffer.read(), dtype=np.uint8)
20
+ return cv2.imdecode(bytes_as_np_array, flags)
21
 
22
  # Download the model file
23
  def download_model():
 
53
  seg_model = tf.keras.models.load_model('seg_unet_model.h5', custom_objects={'Combo_loss': Combo_loss, 'dice_coef': dice_coef})
54
 
55
  inputs = gr.inputs.Image(type="pil", label="Upload an image", source="upload")
56
+ inputs = get_opencv_img_from_buffer(inputs)
57
  image_output = gr.outputs.Image(type="pil", label="Output Image")
58
  # outputs = gr.outputs.HTML() #uncomment for single class output
59
 
60
  def gen_pred(img=inputs, model=seg_model):
 
 
 
 
 
61
  #rgb_path = os.path.join(test_image_dir,img)
62
  #img = cv2.imread(rgb_path)
63
  img = img[::IMG_SCALING[0], ::IMG_SCALING[1]]