Complete the code to import the main library used for Stable Diffusion.
import [1]
The torch library is used for Stable Diffusion because it supports deep learning models and GPU acceleration.
Complete the code to load a pre-trained Stable Diffusion model using the diffusers library.
from diffusers import StableDiffusionPipeline pipeline = StableDiffusionPipeline.from_pretrained([1])
The 'stable-diffusion-v1-4' is a common pre-trained model name for Stable Diffusion in the diffusers library.
Fix the error in the code to generate an image from a text prompt using the pipeline.
image = pipeline([1]="a beautiful sunset over mountains").images[0]
The correct argument name for the text input in the pipeline is prompt.
Fill both blanks to convert the generated image to a numpy array and display its shape.
import numpy as np image_array = np.[1](image) print(image_array.[2])
Use np.array to convert the image to a numpy array, and shape to get its dimensions.
Fill all three blanks to save the generated image to a file named 'output.png'.
from PIL import Image img = Image.[1](image_array) img.[2]('output.png', [3]='PNG')
Use Image.fromarray to create an image from the array, then save it with the format set to 'PNG'.