Skip to content

Commit

Permalink
Merge pull request #47 from SubstrateLabs/chris/interpolation
Browse files Browse the repository at this point in the history
interpolation sdk update
  • Loading branch information
csreesan authored Aug 6, 2024
2 parents 585672f + 8058cc8 commit 0f7b7fc
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 13 deletions.
2 changes: 1 addition & 1 deletion substrate/GEN_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240617.20240802
20240617.20240806
4 changes: 3 additions & 1 deletion substrate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
𐃏 Substrate Python SDK
20240617.20240802
20240617.20240806
"""

from .nodes import (
Expand Down Expand Up @@ -37,6 +37,7 @@
RemoveBackground,
TranscribeSpeech,
DeleteVectorStore,
InterpolateFrames,
Llama3Instruct70B,
Mistral7BInstruct,
MultiInpaintImage,
Expand Down Expand Up @@ -83,6 +84,7 @@
"StableDiffusionXLInpaint",
"StableDiffusionXLControlNet",
"StableVideoDiffusion",
"InterpolateFrames",
"TranscribeSpeech",
"GenerateSpeech",
"RemoveBackground",
Expand Down
52 changes: 48 additions & 4 deletions substrate/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,17 +967,17 @@ class Config:
"""
Use "hosted" to return a video URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the video data will be returned as a base64-encoded string.
"""
output_format: Literal["gif", "mp4"] = "gif"
output_format: Literal["gif", "webp", "mp4", "frames"] = "gif"
"""
Output video format.
"""
seed: Optional[int] = None
"""
Seed for deterministic generation. Default is a random seed.
"""
fps: int = 7
fps: Annotated[int, Field(ge=1)] = 7
"""
Frames per second of the generated video.
Frames per second of the generated video. Ignored if output format is `frames`.
"""
motion_bucket_id: int = 180
"""
Expand All @@ -993,10 +993,54 @@ class StableVideoDiffusionOut(BaseModel):
class Config:
extra = Extra.allow

video_uri: str
video_uri: Optional[str] = None
"""
Generated video.
"""
frame_uris: Optional[List[str]] = None
"""
Generated frames.
"""


class InterpolateFramesIn(BaseModel):
class Config:
extra = Extra.allow

frame_uris: Annotated[List[str], Field(min_items=2)]
"""
Frames.
"""
store: Optional[str] = None
"""
Use "hosted" to return a video URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the video data will be returned as a base64-encoded string.
"""
output_format: Literal["gif", "webp", "mp4", "frames"] = "gif"
"""
Output video format.
"""
fps: Annotated[int, Field(ge=1)] = 7
"""
Frames per second of the generated video. Ignored if output format is `frames`.
"""
num_steps: Annotated[int, Field(ge=1)] = 2
"""
Number of interpolation steps. Each step adds an interpolated frame between adjacent frames. For example, 2 steps over 2 frames produces 5 frames.
"""


class InterpolateFramesOut(BaseModel):
class Config:
extra = Extra.allow

video_uri: Optional[str] = None
"""
Generated video.
"""
frame_uris: Optional[List[str]] = None
"""
Output frames.
"""


class InpaintImageIn(BaseModel):
Expand Down
62 changes: 59 additions & 3 deletions substrate/future_dataclass_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ class FutureStableVideoDiffusionIn:
(Future reference)
Use "hosted" to return a video URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the video data will be returned as a base64-encoded string.
"""
output_format: Literal["gif", "mp4"] = "gif"
output_format: Literal["gif", "webp", "mp4", "frames"] = "gif"
"""
(Future reference)
Output video format.
Expand All @@ -1239,7 +1239,7 @@ class FutureStableVideoDiffusionIn:
fps: int = 7
"""
(Future reference)
Frames per second of the generated video.
Frames per second of the generated video. Ignored if output format is `frames`.
"""
motion_bucket_id: int = 180
"""
Expand All @@ -1259,11 +1259,67 @@ class FutureStableVideoDiffusionOut:
Future reference to FutureStableVideoDiffusionOut
"""

video_uri: str
video_uri: Optional[str] = None
"""
(Future reference)
Generated video.
"""
frame_uris: Optional[List[str]] = None
"""
(Future reference)
Generated frames.
"""


@dataclass
class FutureInterpolateFramesIn:
"""
Future reference to FutureInterpolateFramesIn
"""

frame_uris: List[str]
"""
(Future reference)
Frames.
"""
store: Optional[str] = None
"""
(Future reference)
Use "hosted" to return a video URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the video data will be returned as a base64-encoded string.
"""
output_format: Literal["gif", "webp", "mp4", "frames"] = "gif"
"""
(Future reference)
Output video format.
"""
fps: int = 7
"""
(Future reference)
Frames per second of the generated video. Ignored if output format is `frames`.
"""
num_steps: int = 2
"""
(Future reference)
Number of interpolation steps. Each step adds an interpolated frame between adjacent frames. For example, 2 steps over 2 frames produces 5 frames.
"""


@dataclass
class FutureInterpolateFramesOut:
"""
Future reference to FutureInterpolateFramesOut
"""

video_uri: Optional[str] = None
"""
(Future reference)
Generated video.
"""
frame_uris: Optional[List[str]] = None
"""
(Future reference)
Output frames.
"""


@dataclass
Expand Down
51 changes: 49 additions & 2 deletions substrate/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
RemoveBackgroundOut,
TranscribeSpeechOut,
DeleteVectorStoreOut,
InterpolateFramesOut,
Llama3Instruct70BOut,
Mistral7BInstructOut,
MultiInpaintImageOut,
Expand Down Expand Up @@ -96,6 +97,7 @@
FutureRemoveBackgroundOut,
FutureTranscribeSpeechOut,
FutureDeleteVectorStoreOut,
FutureInterpolateFramesOut,
FutureLlama3Instruct70BOut,
FutureMistral7BInstructOut,
FutureMultiInpaintImageOut,
Expand Down Expand Up @@ -953,7 +955,7 @@ def __init__(
self,
image_uri: str,
store: Optional[str] = None,
output_format: Literal["gif", "mp4"] = "gif",
output_format: Literal["gif", "webp", "mp4", "frames"] = "gif",
seed: Optional[int] = None,
fps: int = 7,
motion_bucket_id: int = 180,
Expand All @@ -967,7 +969,7 @@ def __init__(
store: Use "hosted" to return a video URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the video data will be returned as a base64-encoded string.
output_format: Output video format.
seed: Seed for deterministic generation. Default is a random seed.
fps: Frames per second of the generated video.
fps: Frames per second of the generated video. Ignored if output format is `frames`.
motion_bucket_id: The motion bucket id to use for the generated video. This can be used to control the motion of the generated video. Increasing the motion bucket id increases the motion of the generated video.
noise: The amount of noise added to the conditioning image. The higher the values the less the video resembles the conditioning image. Increasing this value also increases the motion of the generated video.
Expand Down Expand Up @@ -997,6 +999,51 @@ def future(self) -> FutureStableVideoDiffusionOut: # type: ignore
return super().future # type: ignore


class InterpolateFrames(CoreNode[InterpolateFramesOut]):
"""https://substrate.run/nodes#InterpolateFrames"""

def __init__(
self,
frame_uris: List[str],
store: Optional[str] = None,
output_format: Literal["gif", "webp", "mp4", "frames"] = "gif",
fps: int = 7,
num_steps: int = 2,
hide: bool = False,
**kwargs,
):
"""
Args:
frame_uris: Frames.
store: Use "hosted" to return a video URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the video data will be returned as a base64-encoded string.
output_format: Output video format.
fps: Frames per second of the generated video. Ignored if output format is `frames`.
num_steps: Number of interpolation steps. Each step adds an interpolated frame between adjacent frames. For example, 2 steps over 2 frames produces 5 frames.
https://substrate.run/nodes#InterpolateFrames
"""
super().__init__(
frame_uris=frame_uris,
store=store,
output_format=output_format,
fps=fps,
num_steps=num_steps,
hide=hide,
out_type=InterpolateFramesOut,
**kwargs,
)
self.node = "InterpolateFrames"

@property
def future(self) -> FutureInterpolateFramesOut: # type: ignore
"""
Future reference to this node's output.
https://substrate.run/nodes#InterpolateFrames
"""
return super().future # type: ignore


class InpaintImage(CoreNode[InpaintImageOut]):
"""https://substrate.run/nodes#InpaintImage"""

Expand Down
42 changes: 40 additions & 2 deletions substrate/typeddict_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ class StableVideoDiffusionIn(TypedDict):
"""
Use "hosted" to return a video URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the video data will be returned as a base64-encoded string.
"""
output_format: NotRequired[Literal["gif", "mp4"]]
output_format: NotRequired[Literal["gif", "webp", "mp4", "frames"]]
"""
Output video format.
"""
Expand All @@ -832,7 +832,7 @@ class StableVideoDiffusionIn(TypedDict):
"""
fps: NotRequired[int]
"""
Frames per second of the generated video.
Frames per second of the generated video. Ignored if output format is `frames`.
"""
motion_bucket_id: NotRequired[int]
"""
Expand All @@ -849,6 +849,44 @@ class StableVideoDiffusionOut(TypedDict):
"""
Generated video.
"""
frame_uris: NotRequired[List[str]]
"""
Generated frames.
"""


class InterpolateFramesIn(TypedDict):
frame_uris: NotRequired[List[str]]
"""
Frames.
"""
store: NotRequired[str]
"""
Use "hosted" to return a video URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the video data will be returned as a base64-encoded string.
"""
output_format: NotRequired[Literal["gif", "webp", "mp4", "frames"]]
"""
Output video format.
"""
fps: NotRequired[int]
"""
Frames per second of the generated video. Ignored if output format is `frames`.
"""
num_steps: NotRequired[int]
"""
Number of interpolation steps. Each step adds an interpolated frame between adjacent frames. For example, 2 steps over 2 frames produces 5 frames.
"""


class InterpolateFramesOut(TypedDict):
video_uri: NotRequired[str]
"""
Generated video.
"""
frame_uris: NotRequired[List[str]]
"""
Output frames.
"""


class InpaintImageIn(TypedDict):
Expand Down

0 comments on commit 0f7b7fc

Please sign in to comment.