File size: 6,498 Bytes
7d23005
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# 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()