import torch from diffusers import StableDiffusionPipeline import gradio as gr # Load the model model_id = "runwayml/stable-diffusion-v1-5" pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) pipe.to("cuda") # Use GPU for better performance # Function to generate images def generate_image(prompt): image = pipe(prompt).images[0] return image # Create a Gradio interface interface = gr.Interface( fn=generate_image, inputs="text", outputs="image", title="Text-to-Image Generator", description="Enter a text prompt to generate an image using Stable Diffusion." ) # Launch the Gradio app interface.launch()