Spaces:
Runtime error
Runtime error
Update app.py
Browse files82 unmodified lines838485868788899091128 unmodified lines2202212222232242252266 unmodified lines233234235236237238239240241242243244112 unmodified lines35735835936036136249 unmodified lines4124134144154164174186 unmodified lines42542642742842943043182 unmodified lines# Release the video capture objectcap.release()# 'image' is the first frame extracted from video_inreturn first_frame, gr.State([]), gr.State([]), first_frame, first_frame, output_dir, None, None, gr.update(open=False)def get_point(point_type, tracking_points, trackings_input_label, first_frame_path, evt: gr.SelectData):print(f"You selected {evt.value} at {evt.index} from {evt.target}")128 unmodified linesdef sam_process(input_first_frame_image, checkpoint, tracking_points, trackings_input_label, video_frames_dir, progress=gr.Progress(track_tqdm=True)):# 1. We need to preprocess the video and store frames in the right directory# — Penser à utiliser un ID unique pour le dossier6 unmodified linesvideo_dir = video_frames_dir# scan all the JPEG frame names in this directoryframe_names = [p for p in os.listdir(video_dir)if os.path.splitext(p)[-1] in [".jpg", ".jpeg", ".JPG", ".JPEG"]]frame_names.sort(key=lambda p: int(os.path.splitext(p)[0]))inference_state = predictor.init_state(video_path=video_dir)112 unmodified linestracking_points = gr.State([])trackings_input_label = gr.State([])video_frames_dir = gr.State()stored_inference_state = gr.State()stored_frame_names = gr.State()with gr.Column():49 unmodified linesvideo_in.upload(fn = preprocess_video_in,inputs = [video_in],outputs = [first_frame_path, tracking_points, trackings_input_label, input_first_frame_image, points_map, video_frames_dir, stored_inference_state, stored_frame_names, video_in_drawer],queue = False)6 unmodified linessubmit_btn.click(fn = sam_process,inputs = [input_first_frame_image, checkpoint, tracking_points, trackings_input_label, video_frames_dir],outputs = [output_result, stored_frame_names, stored_inference_state])82 unmodified lines83848586878889909192939495969798128 unmodified lines2272282292302312322336 unmodified lines240241242243244245246112 unmodified lines35936036136236336436549 unmodified lines4154164174184194204216 unmodified lines42842943043143243343482 unmodified lines# Release the video capture objectcap.release()# scan all the JPEG frame names in this directoryscanned_frames = [p for p in os.listdir(output_dir)if os.path.splitext(p)[-1] in [".jpg", ".jpeg", ".JPG", ".JPEG"]]scanned_frames.sort(key=lambda p: int(os.path.splitext(p)[0]))# 'image' is the first frame extracted from video_inreturn first_frame, gr.State([]), gr.State([]), first_frame, first_frame, output_dir, scanned_frames, None, None, gr.update(open=False)def get_point(point_type, tracking_points, trackings_input_label, first_frame_path, evt: gr.SelectData):print(f"You selected {evt.value} at {evt.index} from {evt.target}")128 unmodified linesdef sam_process(input_first_frame_image, checkpoint, tracking_points, trackings_input_label, video_frames_dir, scanned_frames, progress=gr.Progress(track_tqdm=True)):# 1. We need to preprocess the video and store frames in the right directory# — Penser à utiliser un ID unique pour le dossier6 unmodified linesvideo_dir = video_frames_dir# scan all the JPEG frame names in this directoryframe_names = scanned_framesinference_state = predictor.init_state(video_path=video_dir)112 unmodified linestracking_points = gr.State([])trackings_input_label = gr.State([])video_frames_dir = gr.State()scanned_frames = gr.State()stored_inference_state = gr.State()stored_frame_names = gr.State()with gr.Column():49 unmodified linesvideo_in.upload(fn = preprocess_video_in,inputs = [video_in],outputs = [first_frame_path, tracking_points, trackings_input_label, input_first_frame_image, points_map, video_frames_dir, scanned_frames, stored_inference_state, stored_frame_names, video_in_drawer],queue = False)6 unmodified linessubmit_btn.click(fn = sam_process,inputs = [input_first_frame_image, checkpoint, tracking_points, trackings_input_label, video_frames_dir, scanned_frames],outputs = [output_result, stored_frame_names, stored_inference_state])
app.py+13-10