jens commited on
Commit
dd4abca
·
1 Parent(s): 4f4f67b
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -51,6 +51,7 @@ with block:
51
 
52
  def on_input_image_upload(input_image):
53
  # encode image on upload
 
54
  return input_image, point_coords_empty(), point_labels_empty(), None
55
  input_image.upload(on_input_image_upload, [input_image], [raw_image, point_coords, point_labels], queue=False)
56
 
@@ -66,19 +67,14 @@ with block:
66
  return img, point_coords, point_labels
67
  input_image.select(on_input_image_select, [input_image, point_coords, point_labels, point_label_radio], [input_image, point_coords, point_labels], queue=False)
68
 
69
- # event - inference
70
- def on_click_sam_encode_btn(inputs):
71
- image = inputs[raw_image]
72
- sam.encode(image)
73
-
74
  def on_click_sam_dencode_btn(inputs):
75
  image = inputs[raw_image]
76
- generated_masks, _ = sam.cond_pred(pts=np.array(inputs[point_coords]), lbls=np.array(inputs[point_labels]))
77
  annotated = (image, [(generated_masks[i], f'Mask {i}') for i in range(len(generated_masks))])
78
  return {masks_annotated_image:annotated,
79
  masks: generated_masks,
80
  cutout_idx: set()}
81
- sam_encode_btn.click(on_click_sam_encode_btn, components, [masks_annotated_image, masks, cutout_idx], queue=True)
82
  sam_decode_btn.click(on_click_sam_dencode_btn, components, [masks_annotated_image, masks, cutout_idx], queue=True)
83
  #sam_sgmt_everything_btn.click(on_sam_sgmt_everything_click, components, [masks_annotated_image, masks, cutout_idx], queue=True)
84
 
 
51
 
52
  def on_input_image_upload(input_image):
53
  # encode image on upload
54
+ sam.encode(input_image)
55
  return input_image, point_coords_empty(), point_labels_empty(), None
56
  input_image.upload(on_input_image_upload, [input_image], [raw_image, point_coords, point_labels], queue=False)
57
 
 
67
  return img, point_coords, point_labels
68
  input_image.select(on_input_image_select, [input_image, point_coords, point_labels, point_label_radio], [input_image, point_coords, point_labels], queue=False)
69
 
 
 
 
 
 
70
  def on_click_sam_dencode_btn(inputs):
71
  image = inputs[raw_image]
72
+ generated_masks, _, _ = sam.cond_pred(pts=np.array(inputs[point_coords]), lbls=np.array(inputs[point_labels]))
73
  annotated = (image, [(generated_masks[i], f'Mask {i}') for i in range(len(generated_masks))])
74
  return {masks_annotated_image:annotated,
75
  masks: generated_masks,
76
  cutout_idx: set()}
77
+ #sam_encode_btn.click(on_click_sam_encode_btn, components, [masks_annotated_image, masks, cutout_idx], queue=True)
78
  sam_decode_btn.click(on_click_sam_dencode_btn, components, [masks_annotated_image, masks, cutout_idx], queue=True)
79
  #sam_sgmt_everything_btn.click(on_sam_sgmt_everything_click, components, [masks_annotated_image, masks, cutout_idx], queue=True)
80