-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython agents.py
More file actions
55 lines (47 loc) · 1.58 KB
/
Copy pathpython agents.py
File metadata and controls
55 lines (47 loc) · 1.58 KB
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
from multiprocessing.connection import Client
from turtle import reset
from IPython.display import Image ,Markdown , display,Video
from google import genai
from google.genai import types
import time
import os
import google.auth as auth
IMAGE_MODEL_ID = "gemini-3.1-flash-image-preview"
TEXT_MODEL_ID = "gemini-3-flash-preview"
prompt = "Draw a picture of a future computer"
client = genai.Client(
api_key="AQ.Ab8RN6JpBoJliEazNQ_Hj5l2CzrwkjGr2eG2Rs1DcJTk_bOe9w"
)
response = client.models.generate_content(
model=IMAGE_MODEL_ID,
contents=prompt
)
for i, part in enumerate(response.candidates[0].content.parts):
if part.inline_data:
with open(f"image_{i}.png", "wb") as f:
f.write(part.inline_data.data)
print("Image saved!")
## video
VIDEO_MODEL_ID = "veo-3.1-fast-generate-001"
def show_video(video, filename):
with open(filename, "wb") as out_file:
out_file.write(video)
display(Video(filename, embed=True, width=600))
operation = client.models.generate_videos(
model=VIDEO_MODEL_ID,
prompt="A person explaining the Pythagorean theorem.",
config=types.GenerateVideosConfig(
aspect_ratio="16:9",
number_of_videos=1,
duration_seconds=8,
resolution="720p",
person_generation="allow_adult",
generate_audio=True,
),
)
while not operation.done:
time.sleep(15)
operation = client.operations.get(operation)
if operation.response:
show_video(operation.result.generated_videos[0].video.video_bytes,
"original.mp4")