sagar007 commited on
Commit
4db07a0
·
verified ·
1 Parent(s): dc23d39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -16,10 +16,8 @@ def segment_everything(image):
16
  segmentation = (preds.numpy() * 255).astype(np.uint8)
17
  return Image.fromarray(segmentation)
18
 
19
- def segment_box(image, box):
20
- if box is None:
21
- return image
22
- x1, y1, x2, y2 = box
23
  cropped_image = image[y1:y2, x1:x2]
24
 
25
  inputs = processor(text=["object"], images=[cropped_image], padding="max_length", return_tensors="pt")
@@ -43,7 +41,12 @@ with gr.Blocks() as demo:
43
  gr.Markdown("# Segment Anything-like Demo")
44
  with gr.Row():
45
  with gr.Column(scale=1):
46
- input_image = gr.Image(label="Input Image", tool="select")
 
 
 
 
 
47
  with gr.Row():
48
  everything_btn = gr.Button("Everything")
49
  box_btn = gr.Button("Box")
@@ -58,7 +61,7 @@ with gr.Blocks() as demo:
58
 
59
  box_btn.click(
60
  fn=segment_box,
61
- inputs=[input_image, input_image],
62
  outputs=[output_image]
63
  )
64
 
 
16
  segmentation = (preds.numpy() * 255).astype(np.uint8)
17
  return Image.fromarray(segmentation)
18
 
19
+ def segment_box(image, x1, y1, x2, y2):
20
+ x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
 
 
21
  cropped_image = image[y1:y2, x1:x2]
22
 
23
  inputs = processor(text=["object"], images=[cropped_image], padding="max_length", return_tensors="pt")
 
41
  gr.Markdown("# Segment Anything-like Demo")
42
  with gr.Row():
43
  with gr.Column(scale=1):
44
+ input_image = gr.Image(label="Input Image")
45
+ with gr.Row():
46
+ x1_input = gr.Number(label="X1")
47
+ y1_input = gr.Number(label="Y1")
48
+ x2_input = gr.Number(label="X2")
49
+ y2_input = gr.Number(label="Y2")
50
  with gr.Row():
51
  everything_btn = gr.Button("Everything")
52
  box_btn = gr.Button("Box")
 
61
 
62
  box_btn.click(
63
  fn=segment_box,
64
+ inputs=[input_image, x1_input, y1_input, x2_input, y2_input],
65
  outputs=[output_image]
66
  )
67