ImageGenerationModel Gallery¶
This section contains the existing ImageGenerationModel
subclasses implemented in distilabel
.
image_generation
¶
AsyncImageGenerationModel
¶
Bases: ImageGenerationModel
Abstract class for asynchronous ImageGenerationModels
, to benefit from the async capabilities
of each LLM implementation. This class is meant to be subclassed by each ImageGenerationModel
, and the
method agenerate
needs to be implemented to provide the asynchronous generation of
responses.
Attributes:
Name | Type | Description |
---|---|---|
_event_loop |
AbstractEventLoop
|
the event loop to be used for the asynchronous generation of responses. |
Source code in src/distilabel/models/image_generation/base.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
generate_parameters
property
¶
Returns the parameters of the agenerate
method.
Returns:
Type | Description |
---|---|
list[Parameter]
|
A list containing the parameters of the |
generate_parsed_docstring
cached
property
¶
Returns the parsed docstring of the agenerate
method.
Returns:
Type | Description |
---|---|
Docstring
|
The parsed docstring of the |
agenerate(input, num_generations=1, **kwargs)
abstractmethod
async
¶
Generates images from the provided input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str
|
the input text to generate the image from. |
required |
num_generations
|
int
|
the number of images to generate. Defaults to |
1
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
A list with a dictionary with the list of images generated. |
Source code in src/distilabel/models/image_generation/base.py
_agenerate(inputs, num_generations=1, **kwargs)
async
¶
Internal function to concurrently generate images for a list of inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
list[str]
|
the list of inputs to generate images for. |
required |
num_generations
|
int
|
the number of generations to generate per input. |
1
|
**kwargs
|
Any
|
the additional kwargs to be used for the generation. |
{}
|
Returns:
Type | Description |
---|---|
list[list[dict[str, Any]]]
|
A list containing the generations for each input. |
Source code in src/distilabel/models/image_generation/base.py
generate(inputs, num_generations=1, **kwargs)
¶
Method to generate a list of images asynchronously, returning the output
synchronously awaiting for the image of each input sent to agenerate
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
list[str]
|
the list of inputs to generate images for. |
required |
num_generations
|
int
|
the number of generations to generate per input. |
1
|
**kwargs
|
Any
|
the additional kwargs to be used for the generation. |
{}
|
Returns:
Type | Description |
---|---|
list[list[dict[str, Any]]]
|
A list containing the images for each input. |
Source code in src/distilabel/models/image_generation/base.py
__del__()
¶
Closes the event loop when the object is deleted.
Source code in src/distilabel/models/image_generation/base.py
InferenceEndpointsImageGeneration
¶
Bases: InferenceEndpointsBaseClient
, AsyncImageGenerationModel
Inference Endpoint image generation implementation running the async API client.
Attributes:
Name | Type | Description |
---|---|---|
model_id |
Optional[str]
|
the model ID to use for the ImageGenerationModel as available in the Hugging Face Hub, which
will be used to resolve the base URL for the serverless Inference Endpoints API requests.
Defaults to |
endpoint_name |
Optional[RuntimeParameter[str]]
|
the name of the Inference Endpoint to use for the LLM. Defaults to |
endpoint_namespace |
Optional[RuntimeParameter[str]]
|
the namespace of the Inference Endpoint to use for the LLM. Defaults to |
base_url |
Optional[RuntimeParameter[str]]
|
the base URL to use for the Inference Endpoints API requests. |
api_key |
Optional[RuntimeParameter[SecretStr]]
|
the API key to authenticate the requests to the Inference Endpoints API. |
Icon
:hugging:
Examples:
Generate images from text prompts:
from distilabel.models.image_generation import InferenceEndpointsImageGeneration
igm = InferenceEndpointsImageGeneration(model_id="black-forest-labs/FLUX.1-schnell", api_key="api.key")
igm.load()
output = igm.generate_outputs(
inputs=["a white siamese cat"],
)
# [{"images": ["iVBORw0KGgoAAAANSUhEUgA..."]}]
Source code in src/distilabel/models/image_generation/huggingface/inference_endpoints.py
agenerate(input, negative_prompt=None, height=None, width=None, num_inference_steps=None, guidance_scale=None, num_generations=1)
async
¶
Generates images from text prompts using huggingface_hub.AsyncInferenceClient.text_to_image
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str
|
Prompt to generate an image from. |
required |
negative_prompt
|
Optional[str]
|
An optional negative prompt for the image generation. Defaults to None. |
None
|
height
|
Optional[float]
|
The height in pixels of the image to generate. |
None
|
width
|
Optional[float]
|
The width in pixels of the image to generate. |
None
|
num_inference_steps
|
Optional[float]
|
The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference. |
None
|
guidance_scale
|
Optional[float]
|
Higher guidance scale encourages to generate images that are closely
linked to the text |
None
|
num_generations
|
int
|
The number of images to generate. Defaults to |
1
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
A list with a dictionary containing a list with the image as a base64 string. |
Source code in src/distilabel/models/image_generation/huggingface/inference_endpoints.py
OpenAIImageGeneration
¶
Bases: OpenAIBaseClient
, AsyncImageGenerationModel
OpenAI image generation implementation running the async API client.
Attributes:
Name | Type | Description |
---|---|---|
model |
str
|
the model name to use for the ImageGenerationModel e.g. "dall-e-3", etc. Supported models can be found here. |
base_url |
Optional[RuntimeParameter[str]]
|
the base URL to use for the OpenAI API requests. Defaults to |
api_key |
Optional[RuntimeParameter[SecretStr]]
|
the API key to authenticate the requests to the OpenAI API. Defaults to
|
max_retries |
RuntimeParameter[int]
|
the maximum number of times to retry the request to the API before
failing. Defaults to |
timeout |
RuntimeParameter[int]
|
the maximum time in seconds to wait for a response from the API. Defaults
to |
Icon
:simple-openai:
Examples:
Generate images from text prompts:
from distilabel.models.image_generation import OpenAIImageGeneration
igm = OpenAIImageGeneration(model="dall-e-3", api_key="api.key")
igm.load()
output = igm.generate_outputs(
inputs=["a white siamese cat"],
size="1024x1024",
quality="standard",
style="natural",
)
# [{"images": ["iVBORw0KGgoAAAANSUhEUgA..."]}]
Source code in src/distilabel/models/image_generation/openai.py
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
agenerate(input, num_generations=1, quality='standard', response_format='url', size=None, style=None)
async
¶
Generates num_generations
images for the given input using the OpenAI async
client. The images are base64 string representations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str
|
A text description of the desired image(s). The maximum length is 1000
characters for |
required |
num_generations
|
int
|
The number of images to generate. Must be between 1 and 10. For |
1
|
quality
|
Optional[Literal['standard', 'hd']]
|
The quality of the image that will be generated. |
'standard'
|
response_format
|
Optional[Literal['url', 'b64_json']]
|
The format in which the generated images are returned. Must be one of |
'url'
|
size
|
Optional[Literal['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792']]
|
The size of the generated images. Must be one of |
None
|
style
|
Optional[Literal['vivid', 'natural']]
|
The style of the generated images. Must be one of |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
A list with a dictionary with the list of images generated. |