From f077320756cfa45c57033c5fa4bf1707be218c7a Mon Sep 17 00:00:00 2001 From: 01du Date: Fri, 22 Nov 2024 11:07:15 +0800 Subject: [PATCH 1/2] seg and clip --- client/py/yidong/client.py | 19 ++++++++++++++++++- client/py/yidong/model.py | 22 ++++++++++++++++++++++ example/gradio/app.py | 2 +- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/client/py/yidong/client.py b/client/py/yidong/client.py index ac6301b..0ee6c66 100644 --- a/client/py/yidong/client.py +++ b/client/py/yidong/client.py @@ -41,6 +41,10 @@ VideoMashupTaskResult, VideoSnapshotTask, VideoSnapshotTaskResult, + VideoSegmentationTask, + VideoSegmentationTaskResult, + VideoClipTask, + VideoClipTaskResult, VideoSummaryTask, VideoSummaryTaskResult, WebhookResponse, @@ -209,7 +213,7 @@ def get_resource(self, id: str) -> Resource: def download_resource(self, id: str, path: str | None = None) -> str: r = self.get_resource(id) - path = path or r.name or f"{r.id}.{r.mime.split('/')[1]}" + path = path or r.name or f"{r.id}.{r.mime.split('/')[1]}" with open(path, "wb") as f: resp = httpx.get(r.url) f.write(resp.content) @@ -386,6 +390,19 @@ def video_concat( """Concatenate multiple videos into one. If `chapters` are provided, they should be of the same length as `video_ids`.""" return self._submit_task(locals()) + def video_segmentation( + self, video_id: str + ) -> TaskRef[VideoSegmentationTask, VideoSegmentationTaskResult]: + """Slicing long videos into segments""" + return self._submit_task(locals()) + + def video_clip( + self, video_id: str, chapters: list[Chapter] + ) -> TaskRef[VideoClipTask, VideoClipTaskResult]: + """Clip the video with the given chapters.""" + return self._submit_task(locals()) + + def video_snapshot( self, video_id: str, *, start: float = 0.0, step: int = 1, stop: float = 0.0 ) -> TaskRef[VideoSnapshotTask, VideoSnapshotTaskResult]: diff --git a/client/py/yidong/model.py b/client/py/yidong/model.py index 70fe3f8..ff20683 100644 --- a/client/py/yidong/model.py +++ b/client/py/yidong/model.py @@ -205,7 +205,25 @@ class VideoSnapshotTask(BaseModel): class VideoSnapshotTaskResult(BaseModel): type: Literal["video_snapshot"] = "video_snapshot" image_ids: list[str] + +class VideoSegmentationTask(BaseModel): + type: Literal["video_segmentation"] = "video_segmentation" + video_id: str + +class VideoSegmentationTaskResult(BaseModel): + type: Literal["video_segmentation"] = "video_segmentation" + chapters: list[Chapter] + +class VideoClipTask(BaseModel): + type: Literal["video_clip"] = "video_clip" + video_id: str + chapters: list[Chapter] + +class VideoClipTaskResult(BaseModel): + type: Literal["video_clip"] = "video_clip" + video_ids: list[str] + class DiffusionModel(StrEnum): SDXL = "sdxl" @@ -239,6 +257,8 @@ class ImageGenerationTaskResult(BaseModel): GenScriptTask, VideoMashupTask, VideoConcatTask, + VideoSegmentationTask, + VideoClipTask, VideoSnapshotTask, ImageGenerationTask, ], @@ -254,6 +274,8 @@ class ImageGenerationTaskResult(BaseModel): GenScriptTaskResult, VideoMashupTaskResult, VideoConcatTaskResult, + VideoSegmentationTaskResult, + VideoClipTaskResult, VideoSnapshotTaskResult, ImageGenerationTaskResult, ], diff --git a/example/gradio/app.py b/example/gradio/app.py index 0ba8f3a..41cc4d4 100644 --- a/example/gradio/app.py +++ b/example/gradio/app.py @@ -39,4 +39,4 @@ def call_api(user_email): default_concurrency_limit=10, ) - clip_service.launch(ssr_mode=False) + clip_service.launch(ssr_mode=False) \ No newline at end of file From ba2459e994130df01bf46e52907b237a52c00ae0 Mon Sep 17 00:00:00 2001 From: 01du Date: Wed, 20 Nov 2024 17:12:08 +0800 Subject: [PATCH 2/2] one fix --- client/py/yidong/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/py/yidong/client.py b/client/py/yidong/client.py index 0ee6c66..e1b6cb1 100644 --- a/client/py/yidong/client.py +++ b/client/py/yidong/client.py @@ -311,8 +311,8 @@ def get_task( f"failed to fetch task [{id}] result within {timeout} seconds" ) sleep(poll_interval) - else: - return self._get_task(id) + + return self._get_task(id) def delete_task(self, tid: str) -> bool: return self._request(bool, "delete", f"/task/{tid}")