Skip to content

Commit 7eb5b07

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add Video.from_file() support in Python SDK
PiperOrigin-RevId: 768226571
1 parent c00c4a9 commit 7eb5b07

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

google/genai/types.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7133,6 +7133,30 @@ class Video(_common.BaseModel):
71337133
default=None, description="""Video encoding, for example "video/mp4"."""
71347134
)
71357135

7136+
@classmethod
7137+
def from_file(
7138+
cls, *, location: str, mime_type: Optional[str] = None
7139+
) -> 'Video':
7140+
"""Loads a video from a local file.
7141+
7142+
Args:
7143+
location: The local path to load the video from.
7144+
mime_type: The MIME type of the video. If not provided, the MIME type
7145+
will be automatically determined.
7146+
7147+
Returns:
7148+
A loaded video as an `Video` object.
7149+
"""
7150+
import mimetypes # pylint: disable=g-import-not-at-top
7151+
import pathlib # pylint: disable=g-import-not-at-top
7152+
7153+
video_bytes = pathlib.Path(location).read_bytes()
7154+
7155+
if not mime_type:
7156+
mime_type, _ = mimetypes.guess_type(location)
7157+
video = cls(video_bytes=video_bytes, mime_type=mime_type)
7158+
return video
7159+
71367160
def save(
71377161
self,
71387162
path: str,

0 commit comments

Comments
 (0)