Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/dtl #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions client/py/yidong/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
VideoMashupTaskResult,
VideoSnapshotTask,
VideoSnapshotTaskResult,
VideoSegmentationTask,
VideoSegmentationTaskResult,
VideoClipTask,
VideoClipTaskResult,
VideoSummaryTask,
VideoSummaryTaskResult,
WebhookResponse,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -307,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}")
Expand Down Expand Up @@ -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]:
Expand Down
22 changes: 22 additions & 0 deletions client/py/yidong/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -239,6 +257,8 @@ class ImageGenerationTaskResult(BaseModel):
GenScriptTask,
VideoMashupTask,
VideoConcatTask,
VideoSegmentationTask,
VideoClipTask,
VideoSnapshotTask,
ImageGenerationTask,
],
Expand All @@ -254,6 +274,8 @@ class ImageGenerationTaskResult(BaseModel):
GenScriptTaskResult,
VideoMashupTaskResult,
VideoConcatTaskResult,
VideoSegmentationTaskResult,
VideoClipTaskResult,
VideoSnapshotTaskResult,
ImageGenerationTaskResult,
],
Expand Down
2 changes: 1 addition & 1 deletion example/gradio/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)