Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalandi committed Sep 11, 2024
1 parent 4f9192d commit ab266cf
Show file tree
Hide file tree
Showing 2 changed files with 485 additions and 3,047 deletions.
39 changes: 39 additions & 0 deletions notebooks/segment-anything/gradio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,42 @@ def get_select_coords(img, evt: gr.SelectData):
input_img.upload(on_image_change, [input_img], [input_img])

return demo


def make_video_demo(segmenter, sample_path):
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
input_video = gr.Video(label="Video")
coordinates = gr.Textbox(label="Coordinates")
labels = gr.Textbox(label="Labels")
submit_btn = gr.Button(value="Segment")
with gr.Column():
output_video = gr.Video(label="Output video")

def on_video_change(video):
segmenter.set_video(video)
return video

def segment_video(video, coordinates_txt, labels_txt):
coordinates_np = []
for coords in coordinates_txt.split(";"):
temp = [float(numb) for numb in coords.split(",")]
coordinates_np.append(temp)

labels_np = []
for l in labels_txt.split(","):
labels_np.append(int(l))
segmenter.set_video(video)
segmenter.add_new_points_or_box(coordinates_np, labels_np)
segmenter.propagate_in_video()
video_out_path = segmenter.save_as_video(640, 360)

return video_out_path

submit_btn.click(segment_video, inputs=[input_video, coordinates, labels], outputs=[output_video])
input_video.upload(on_video_change, [input_video], [input_video])

examples = gr.Examples(examples=[[sample_path / "coco.mp4", "430, 130; 500, 100", "1, 1"]], inputs=[input_video, coordinates, labels])

return demo
Loading

0 comments on commit ab266cf

Please sign in to comment.