text2img

Function

Interacts with Stable Diffusion services to generate images via text and obtains the inference result of a Stable Diffusion model.

The request body data format is as follows:

{
"prompt": text generation prompt,
"output_format": format of the generated image,
"size": size of the generated image,
"model_name": model name
}

Prototype

def text2img(prompt, output_format, size)

Parameters

Parameter

Data Type

Required/Optional

Description

prompt

str

Required

Prompt for generating an image. The length range is [1, 1024 × 1024].

output_format

str

Optional

Format of the generated image. The value can be png, jpeg, jpg, or webp. The default value is png.

size

str

Optional

Image size, in the format of "height × width". The supported size depends on the corresponding foundation model. The value needs to meet the regular expression requirement: "^\d{1,5}\*\d{1,5}$". The default value is 512 × 512.

Return Value

Data Type

Description

dict

The return format is {"prompt": prompt, "result": data}, where prompt indicates the prompt for generating an image, and result indicates the Base64-encoded image data of the foundation model inference result.