图片编辑
step-1x-edit 模型限时免费调用中
请求地址
POST https://api.stepfun.com/v1/images/edits
请求参数
-
modelstringrequired
需要使用的模型名称,当前仅支持step-1x-edit -
imagefilerequired
传入的图片文件,当前仅支持传入一个图片;
图片分辨率:最小为 64px,最大为1728像素,最大像素面积不可超过 1024x1024;;
支持文件格式:jpg,png,webp;
图片尺寸大小:10MB 文件尺寸比例:需大于等于 1:3 and 小于等于 3:1。 -
promptstringrequired
图像的文本描述,最大长度为 512 个字符 -
seedintoptional
随机种子,当不传或传入为 0 时,使用系统随机生成的种子。 -
stepsintoptional
生成步数,当前支持 1 ~ 100 之间整数。默认为 28。 -
cfg_scalefloatoptional
classifier-free guidance scale,当前支持 1 ~10 之间的数字。默认为 6。 -
sizestringoptional
生成图片的大致尺寸,默认值为512x512;可选项如下:- 512x512
- 768x768
- 1024x1024
尺寸逻辑: 1. 当图片输入为 1:1 时,会按照 size 进行输出; 2. 当图片输入比例不为 1:1 时,会按照用户提供的图片计算比例,且输出图像尺寸面积约等于size * size;
-
response_formatstringoptional
生成的图片返回的格式。支持参数为b64_json或url。默认为url。
请求响应
createdint
创建图片时的时间戳,精确到秒级别dataobject array
计算token返回数据 -seedint
生成时传入的 Seed 或系统随机生成的 Seed。相同的 Seed 有助于生成类似的图片。 -finish_reasonstring
生成停止的原因,如果为 success ,则为成功生成;为 content_filtered 表示生成成功,但命中检测所以停止。 -b64_jsonstring
生成的图片的 Base64 编码。当 response_format 设置为 b64_json 时,返回此字段。 -urlstring
生成的图片的下载链接。当 response_format 设置为 url 时,返回此字段。
{
"created": 1589478378,
"data": [
{
"b64_json": "AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1",
"finish_reason": "success",
"seed": 123838
}
]
}示例
import base64
from openai import OpenAI
client = OpenAI(api_key = STEP_API_KEY, base_url = "https://api.stepfun.com/v1")
prompt = """
变成一只英短猫
"""
result = client.images.edit(
model = "step-1x-edit",
image = open("cat.jpg", "rb"),
prompt = prompt,
response_format = "b64_json",
extra_body = {
"cfg_scale": 10.0,
"steps": 20,
"seed": 1
},
)
print(result)
image_base64 = result.data[0].b64_json
image_bytes = base64.b64decode(image_base64)
# Save the image to a file
with open("cat-on-rooftop.png", "wb") as f:
f.write(image_bytes)
Last updated on