Spaces:
Runtime error
Runtime error
import torch | |
from diffusers import StableDiffusionPipeline | |
import gradio as gr | |
# Load Stable Diffusion model from Hugging Face | |
model_id = "runwayml/stable-diffusion-v1-5" # Change to "stabilityai/stable-diffusion-xl-base-1.0" for SDXL | |
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) | |
pipe.to("cuda") # Use "cpu" if no GPU is available | |
def generate_image(prompt): | |
image = pipe(prompt).images[0] | |
return image | |
# Create Gradio UI | |
demo = gr.Interface( | |
fn=generate_image, | |
inputs=gr.Textbox(label="Enter your prompt"), | |
outputs=gr.Image(), | |
title="Stable Diffusion Image Generator" | |
) | |
demo.launch() | |