# Import the necessary libraries from diffusers import StableDiffusionPipeline import torch from PIL import Image import gradio as gr # Load the Stable Diffusion model model_id = "runwayml/stable-diffusion-v1-5" pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) # Use CPU as fallback if CUDA is not available device = "cuda" if torch.cuda.is_available() else "cpu" pipe = pipe.to(device) # Function to generate an image def generate_image(prompt): image = pipe(prompt).images[0] return image # Define the Gradio interface with gr.Blocks() as demo: gr.HTML( """