aryswisnu commited on
Commit
5ba9555
1 Parent(s): 91171fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -5
app.py CHANGED
@@ -44,7 +44,7 @@ def get_masks(prompts, img, threhsold):
44
  return masks
45
 
46
 
47
- def extract_image(img, pos_prompts, neg_prompts, threshold, alpha_value=0.5, blur_radius=5):
48
  positive_masks = get_masks(pos_prompts, img, threshold)
49
  negative_masks = get_masks(neg_prompts, img, threshold)
50
 
@@ -53,9 +53,6 @@ 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
- 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
60
  fig, ax = plt.subplots()
61
  ax.imshow(img)
@@ -72,7 +69,6 @@ def extract_image(img, pos_prompts, neg_prompts, threshold, alpha_value=0.5, blu
72
  return output_image, final_mask, inverse_mask
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>"
 
44
  return masks
45
 
46
 
47
+ def extract_image(img, pos_prompts, neg_prompts, threshold, alpha_value):
48
  positive_masks = get_masks(pos_prompts, img, threshold)
49
  negative_masks = get_masks(neg_prompts, img, threshold)
50
 
 
53
  neg_mask = np.any(np.stack(negative_masks), axis=0)
54
  final_mask = pos_mask & ~neg_mask
55
 
 
 
 
56
  # blend the original image and the mask using the alpha value
57
  fig, ax = plt.subplots()
58
  ax.imshow(img)
 
69
  return output_image, final_mask, inverse_mask
70
 
71
 
 
72
  title = "Interactive demo: zero-shot image segmentation with CLIPSeg"
73
  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."
74
  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>"