forked from digitalocean/pydo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_generation.py
More file actions
35 lines (25 loc) · 949 Bytes
/
Copy pathimage_generation.py
File metadata and controls
35 lines (25 loc) · 949 Bytes
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
"""Generate an image with the Gradient AI Platform and save it to disk.
Uses the inference-focused ``pydo.inference.Client`` entry point so the
top-level surface (``dir(client)``, IDE autocomplete) stays focused on
inference primitives.
Usage:
# The PAT must be created with FULL ACCESS scope to call inference APIs.
export DIGITALOCEAN_TOKEN="your-full-access-pat"
python examples/inference/image_generation.py
"""
import base64
import os
from pydo.inference import Client
def main() -> None:
client = Client(token=os.environ["DIGITALOCEAN_TOKEN"])
result = client.images.generate(
model="openai-gpt-image-1",
prompt="A friendly shark typing on a laptop at a sunny beach",
n=1,
)
output_path = "output.png"
with open(output_path, "wb") as f:
f.write(base64.b64decode(result.data[0].b64_json))
print(f"Image saved as {output_path}")
if __name__ == "__main__":
main()