aryswisnu commited on
Commit
91171fa
1 Parent(s): 111ac37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -6
app.py CHANGED
@@ -1,6 +1,6 @@
1
  from transformers import CLIPSegProcessor, CLIPSegForImageSegmentation
2
  import gradio as gr
3
- from PIL import Image, ImageFilter
4
  import torch
5
  import matplotlib.pyplot as plt
6
  import torch
@@ -53,10 +53,7 @@ def extract_image(img, pos_prompts, neg_prompts, threshold, alpha_value=0.5, blu
53
  neg_mask = np.any(np.stack(negative_masks), axis=0)
54
  final_mask = pos_mask & ~neg_mask
55
 
56
- # apply Gaussian blur for feathering
57
- final_mask_img = Image.fromarray((final_mask * 255).astype(np.uint8), "L")
58
- final_mask_img = final_mask_img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
59
- final_mask = np.array(final_mask_img) / 255
60
  final_mask = final_mask > threshold
61
 
62
  # blend the original image and the mask using the alpha value
@@ -76,7 +73,6 @@ def extract_image(img, pos_prompts, neg_prompts, threshold, alpha_value=0.5, blu
76
 
77
 
78
 
79
-
80
  title = "Interactive demo: zero-shot image segmentation with CLIPSeg"
81
  description = "Demo for using CLIPSeg, a CLIP-based model for zero- and one-shot image segmentation. To use it, simply upload an image and add a text to mask (identify in the image), or use one of the examples below and click 'submit'. Results will show up in a few seconds."
82
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2112.10003'>CLIPSeg: Image Segmentation Using Text and Image Prompts</a> | <a href='https://huggingface.co/docs/transformers/main/en/model_doc/clipseg'>HuggingFace docs</a></p>"
 
1
  from transformers import CLIPSegProcessor, CLIPSegForImageSegmentation
2
  import gradio as gr
3
+ from PIL import Image
4
  import torch
5
  import matplotlib.pyplot as plt
6
  import torch
 
53
  neg_mask = np.any(np.stack(negative_masks), axis=0)
54
  final_mask = pos_mask & ~neg_mask
55
 
56
+ final_mask = Image.fromarray(final_mask.astype(np.uint8) * 255, "L")
 
 
 
57
  final_mask = final_mask > threshold
58
 
59
  # blend the original image and the mask using the alpha value
 
73
 
74
 
75
 
 
76
  title = "Interactive demo: zero-shot image segmentation with CLIPSeg"
77
  description = "Demo for using CLIPSeg, a CLIP-based model for zero- and one-shot image segmentation. To use it, simply upload an image and add a text to mask (identify in the image), or use one of the examples below and click 'submit'. Results will show up in a few seconds."
78
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2112.10003'>CLIPSeg: Image Segmentation Using Text and Image Prompts</a> | <a href='https://huggingface.co/docs/transformers/main/en/model_doc/clipseg'>HuggingFace docs</a></p>"