File size: 670 Bytes
2397aa5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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()
|