runpod
: The SDK used to interact with Runpod’s serverless environment.torch
: PyTorch library, necessary for running deep learning models and ensuring they utilize the GPU.diffusers
: Provides methods to work with diffusion models like Stable Diffusion.BytesIO
and base64
: Used to handle image data conversions.model_id
specifies the model identifier for Stable Diffusion version 1.5.StableDiffusionPipeline.from_pretrained
loads the model weights into memory with a specified tensor type.pipe.to("cuda")
moves the model to the GPU for faster computation.BytesIO
: Creates an in-memory binary stream to which the image is saved.base64.b64encode
: Encodes the binary data to a base64 format, which is then decoded to a UTF-8 string.prompt
from the input event.model
to generate an image.stable_diffusion_handler
function to handle incoming requests.
test_input.json
file with the following content:
torch
, diffusers
) are included in your environment or requirements file when deploying.