-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_image.py
More file actions
77 lines (61 loc) · 1.94 KB
/
basic_image.py
File metadata and controls
77 lines (61 loc) · 1.94 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""Basic image generation examples.
Demonstrates text-to-image, image-to-image, upscale, and background removal.
Usage:
export DEAPI_API_KEY="sk-your-api-key"
python examples/basic_image.py
"""
from deapi import DeapiClient
client = DeapiClient()
# --- Check price before generating ---
price = client.images.generate_price(
prompt="a cat floating in a nebula, photorealistic",
model="Flux1schnell",
width=1024,
height=1024,
seed=42,
)
print(f"Generation will cost: ${price.price}")
# --- Text-to-image ---
print("\nGenerating image...")
job = client.images.generate(
prompt="a cat floating in a nebula, photorealistic",
negative_prompt="blurry, low quality, distorted",
model="Flux1schnell",
width=1024,
height=1024,
seed=42,
)
print(f"Job submitted: {job.request_id}")
result = job.wait()
print(f"Status: {result.status}")
print(f"Image URL: {result.result_url}")
if result.results_alt_formats:
print(f"Alt formats: {result.results_alt_formats}")
# --- Image-to-image (transform an existing image) ---
# Uncomment to run — requires an image file:
#
# print("\nTransforming image...")
# job = client.images.transform(
# prompt="make it look like a watercolor painting",
# image="photo.jpg", # accepts str path, Path, bytes, or file-like
# model="QwenImageEdit_Plus_NF4",
# steps=30,
# seed=42,
# )
# result = job.wait()
# print(f"Transformed: {result.result_url}")
# --- Image upscale ---
# Uncomment to run — requires an image file:
#
# print("\nUpscaling image...")
# job = client.images.upscale(image="low_res.png", model="RealESRGAN_x4")
# result = job.wait()
# print(f"Upscaled: {result.result_url}")
# --- Background removal ---
# Uncomment to run — requires an image file:
#
# print("\nRemoving background...")
# job = client.images.remove_background(image="photo.png", model="Ben2")
# result = job.wait()
# print(f"Background removed: {result.result_url}")
client.close()