Parameter Format for Serverless Inference (Text to Image)
Hey... thank you for sharing this with the community. Your code works great, and I'm curious to know how you got it running - because the official docs at https://huggingface.co/docs/api-inference/tasks/text-to-image are TOTALLY wrong Bringing this up so that the information is clearly laid out for other devs who might attempt to use the Serverless Inference endpoint for image generation tasks. BTW... if you work for HF or know anyone involved in maintaining the documentation, please let them know that the text-to-image interface laid out in the docs is VERY different from the actual interface for interacting with these models.
Because this issue really should be fixed - I know documentation is never a priority in a fast growing startup, but something like an API reference really needs to be accurate!
Here is a comparison between what's in the docs, and the actual code in your space, which appears to work perfectly.
DOCUMENTED VERSION (Does Not Work):
- inputs* string The input text data (sometimes called “prompt”)
- parameters object Additional inference parameters for Text To Image
- guidance_scale number A higher guidance scale value encourages the model to generate images closely linked to the text prompt, but values too high may cause saturation and other artifacts.
- negative_prompt string[] One or several prompt to guide what NOT to include in image generation.
- num_inference_steps integer The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference.
- target_size object The size in pixel of the output image
- width* integer
- height* integer
- scheduler string Override the scheduler with a compatible one.
- seed integer Seed for the random number generator.
NYMBO'S VERSION (Works Amazing):
payload = {
"inputs": prompt,
"is_negative": is_negative,
"steps": steps,
"cfg_scale": cfg_scale,
"seed": seed if seed != -1 else random.randint(1, 1000000000),
"strength": strength,
"parameters": {
"width": width, # Pass the width to the API
"height": height # Pass the height to the API
}
}
PS. Happy to help with fixing these docs... I'm not technically a technical writer, but I like to think I write better than the average developer :)