stable-diffusion-v1-5-img2img Beta
Text-to-Image • RunwayMLStable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images. Img2img generate a new image from an input image with Stable Diffusion.
| Model Info | |
|---|---|
| Terms and License | link ↗ |
| More information | link ↗ |
| Beta | Yes |
| Unit Pricing | $0.00 per step |
Usage
export interface Env { AI: Ai;}
export default { async fetch(request, env): Promise<Response> {
// Picture of a dog const exampleInputImage = await fetch( "https://pub-1fb693cb11cc46b2b2f656f51e015a2c.r2.dev/dog.png" );
const inputs = { prompt: "Change to a lion", image: [...new Uint8Array(await exampleInputImage.arrayBuffer())], };
const response = await env.AI.run( "@cf/runwayml/stable-diffusion-v1-5-img2img", inputs );
return new Response(response, { headers: { "content-type": "image/png", }, }); },} satisfies ExportedHandler<Env>;curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/runwayml/stable-diffusion-v1-5-img2img \ -X POST \ -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ -d '{ "prompt": "cyberpunk cat" }'Parameters
prompt
stringrequiredminLength: 1A text description of the image you want to generatenegative_prompt
stringText describing elements to avoid in the generated imageheight
integerminimum: 256maximum: 2048The height of the generated image in pixelswidth
integerminimum: 256maximum: 2048The width of the generated image in pixels▶image[]
arrayFor use with img2img tasks. An array of integers that represent the image data constrained to 8-bit unsigned integer valuesimage_b64
stringFor use with img2img tasks. A base64-encoded string of the input image▶mask[]
arrayAn array representing An array of integers that represent mask image data for inpainting constrained to 8-bit unsigned integer valuesnum_steps
integerdefault: 20maximum: 20The number of diffusion steps; higher values can improve quality but take longerstrength
numberdefault: 1A value between 0 and 1 indicating how strongly to apply the transformation during img2img tasks; lower values make the output closer to the input imageguidance
numberdefault: 7.5Controls how closely the generated image should adhere to the prompt; higher values make the image more aligned with the promptseed
integerRandom seed for reproducibility of the image generation
The binding returns a ReadableStream with the
output (check the model's output schema).