nielsr HF staff commited on
Commit
965c521
1 Parent(s): 8483f38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -14,20 +14,22 @@ def process_image(image, prompt):
14
  # predict
15
  with torch.no_grad():
16
  outputs = model(**inputs)
17
- preds = outputs.logits.unsqueeze(1)
18
 
19
  filename = f"mask.png"
20
- plt.imsave(filename,torch.sigmoid(preds[0][0]))
21
 
22
- img2 = cv2.imread(filename)
23
- gray_image = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
24
 
25
- (thresh, bw_image) = cv2.threshold(gray_image, 100, 255, cv2.THRESH_BINARY)
26
 
27
- # fix color format
28
- cv2.cvtColor(bw_image, cv2.COLOR_BGR2RGB)
29
 
30
- return Image.fromarray(bw_image)
 
 
31
 
32
  title = "Interactive demo: zero-shot image segmentation with CLIPSeg"
33
  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."
@@ -36,7 +38,7 @@ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2112.100
36
  examples = [["example_image.png", "wood"]]
37
 
38
  interface = gr.Interface(fn=process_image,
39
- inputs=[gr.Image(type="pil"), gr.Textbox(label="What do you want to identify (separated by comma)?")],
40
  outputs=gr.Image(type="pil"),
41
  title=title,
42
  description=description,
 
14
  # predict
15
  with torch.no_grad():
16
  outputs = model(**inputs)
17
+ preds = outputs.logits
18
 
19
  filename = f"mask.png"
20
+ plt.imsave(filename, torch.sigmoid(preds))
21
 
22
+ # # img2 = cv2.imread(filename)
23
+ # # gray_image = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
24
 
25
+ # # (thresh, bw_image) = cv2.threshold(gray_image, 100, 255, cv2.THRESH_BINARY)
26
 
27
+ # # # fix color format
28
+ # # cv2.cvtColor(bw_image, cv2.COLOR_BGR2RGB)
29
 
30
+ # # return Image.fromarray(bw_image)
31
+
32
+ # return Image.open("mask.png").convert("RGB")
33
 
34
  title = "Interactive demo: zero-shot image segmentation with CLIPSeg"
35
  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."
 
38
  examples = [["example_image.png", "wood"]]
39
 
40
  interface = gr.Interface(fn=process_image,
41
+ inputs=[gr.Image(type="pil"), gr.Textbox(label="Please describe what you want to identify")],
42
  outputs=gr.Image(type="pil"),
43
  title=title,
44
  description=description,