# import argparse | |
# import gradio as gr | |
# import cv2 | |
# import os | |
# import numpy as np | |
# from gradio_image_prompter import ImagePrompter | |
# def video_to_interaction(input_video, frame_selector): | |
# """ | |
# 1. get the frame from input_video. | |
# 2. get the interaction from the frame. | |
# 3. return the interaction. | |
# Args: | |
# input_video (_type_): _description_ | |
# frame_selector (_type_): _description_ | |
# interaction (_type_): _description_ | |
# """ | |
# frames = cv2.VideoCapture(input_video) | |
# interaction = None | |
# # fps = int(frames.get(cv2.CAP_PROP_FPS)) | |
# frame_id = 0 | |
# if not frames.isOpened(): | |
# gr.Info("Error opening video file") | |
# else: | |
# while frames.isOpened(): | |
# ret, frame = frames.read() | |
# print(frame_id, frame_selector) | |
# if frame_id == frame_selector: | |
# interaction = np.array(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)) | |
# break | |
# frame_id += 1 | |
# frames.release() | |
# if interaction is None: | |
# gr.Info("Frame not found") | |
# raise ValueError("Frame not found") | |
# return {"image": interaction, "points": []} | |
# # VideoEditingDemoUrl = "xxx" | |
# # ### Point Trajectory Demo [[VideoEditing Demo]]({VideoEditingDemoUrl}) | |
# ProjectPage = "https://taptr.github.io" | |
# CodeUrl = "https://taptr.github.io" | |
# PaperUrlV1 = "https://arxiv.org/abs/2403.13042" | |
# PaperUrlV2 = "https://arxiv.org/abs/2407.16291" | |
# PaperUrlV3 = "https://arxiv.org/abs/2411.18671" | |
# with gr.Blocks(title="TAPTRv3") as demo: | |
# title_markdown = (f""" | |
# # TAPTRv3: Spatial and Temporal Context Foster Robust Tracking of Any Point in Long Video | |
# ## TAPTR: Track Any Point TRansformer | |
# [[TAPTR-Series Project Page]]({ProjectPage}) [[TAPTR-Series Repository]]({CodeUrl}) [[Paper-TAPTRv1]]({PaperUrlV1}) [[Paper-TAPTRv2]]({PaperUrlV2}) [[Paper-TAPTRv3]]({PaperUrlV3}) | |
# """) | |
# tips = (f""" | |
# **Usage** \\ | |
# 1. Upload a video in Input Video module. \\ | |
# 2. Select a frame in Frame Selector module, the corresponding frame will be shown in Interaction module. (The first frame is selected by default.) \\ | |
# 3. Click on the Interaction module to specify the points to be tracked. \\ | |
# 4. Click on Submit button to start tracking the points. \\ | |
# 5. The output video will be shown in Output Video module. \\ | |
# More details, please refer to the example video. \\ | |
# **Note** \\ | |
# 1. TAPTR has broad application scenarios, such as slam, AR, motion capture, and video editing. If you have any collaboration intentions, please contact us. \\ | |
# 2. Limited by the hardware our demo running on, a video that is too long may result in the long machine occupation, so we reject the video longer than 600 frames. \\ | |
# 3. If you have any questions feel free to contact us or open an issue in our [repo]({CodeUrl}). | |
# """) | |
# gr.Markdown(title_markdown) | |
# with gr.Row(): | |
# with gr.Column(scale=0.5): | |
# input_video = gr.Video(label="Input Video", height=300) | |
# use_globalmatching = gr.Checkbox(label="Automatically Trigger Global Matching to Reestablish Tracking.", value=False) | |
# user_specified_retrack = gr.Textbox(label="Manually Specify Frames for Global Matching to Reestablish Tracking.", placeholder="[ ]") | |
# frame_selector = gr.Slider(minimum=0, maximum=20, value=0, label="Frame Selector") | |
# submit_btn = gr.Button("Submit") | |
# if os.path.exists("./assets/example_videos/Box.mp4"): | |
# with gr.Row(): | |
# gr.Examples(examples=[ | |
# [f"./assets/example_videos/Box.mp4"], | |
# ], inputs=[input_video], label="Example-Box") | |
# gr.Examples(examples=[ | |
# [f"./assets/example_videos/Sofa.mp4"], | |
# ], inputs=[input_video], label="Example-Sofa") | |
# gr.Examples(examples=[ | |
# [f"./assets/example_videos/RabbitAndYogurt.mp4"], | |
# ], inputs=[input_video], label="Example-RabbitAndYogurt") | |
# gr.Examples(examples=[ | |
# [f"./assets/example_videos/RollingBasketball.mp4"], | |
# ], inputs=[input_video], label="Example-RollingBasketball") | |
# gr.Examples(examples=[ | |
# [f"./assets/example_videos/Goldfish.mp4"], | |
# ], inputs=[input_video], label="Example-Goldfish") | |
# gr.Examples(examples=[ | |
# [f"./assets/example_videos/Jellyfish.mp4"], | |
# ], inputs=[input_video], label="Example-Jellyfish") | |
# gr.Examples(examples=[ | |
# [f"./assets/example_videos/HandOcclusion.mp4"], | |
# ], inputs=[input_video], label="Example-HandOcclusion") | |
# gr.Examples(examples=[ | |
# [f"./assets/example_videos/PaperOcclusion.mp4"], | |
# ], inputs=[input_video], label="Example-PaperOcclusion") | |
# if os.path.exists("./assets/PointTracking.mp4"): | |
# usage_video = gr.Video(label="Usage", height=250, value="./assets/PointTracking.mp4") | |
# gr.Markdown(tips) | |
# with gr.Column(): | |
# interaction = ImagePrompter(label="Interaction", interactive=True, height=650) | |
# output_video = gr.Video(label="Output Video", height=650) | |
# input_video.change(fn=video_to_interaction, inputs=[input_video, frame_selector], outputs=[interaction]) | |
# frame_selector.change(fn=video_to_interaction, inputs=[input_video, frame_selector], outputs=[interaction]) | |
# submit_btn.click(fn=process_one_video, inputs=[input_video, frame_selector, interaction, use_globalmatching, user_specified_retrack], outputs=[output_video]) | |
# demo.queue() | |
# if __name__ == "__main__": | |
# global DemoCore | |
# args = get_args() | |
# DemoCore = Demo(args) | |
# demo.launch(server_name="0.0.0.0", server_port=10006) | |
import gradio as gr | |
# ζ¬ε°ζε‘ηε ¬η½ URL | |
LOCAL_DEMO_URL = "taptr.deepdataspace.com" | |
# ε θ½½ζ¬ε° Demo | |
demo = gr.Blocks.load(LOCAL_DEMO_URL) | |
# ε―ε¨ Hugging Face η Gradio ηι’ | |
if __name__ == "__main__": | |
demo.launch() |