Spaces:
Running
on
Zero
Running
on
Zero
import gradio as gr | |
from diffusers import StableDiffusionPipeline | |
import torch | |
# Model load | |
model_id = "runwayml/stable-diffusion-v1-5" | |
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) | |
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") | |
# Function | |
def generate(prompt): | |
image = pipe(prompt).images[0] | |
return image | |
# Gradio UI | |
demo = gr.Interface( | |
fn=generate, | |
inputs=gr.Textbox(label="Enter your prompt"), | |
outputs=gr.Image(type="pil", label="Generated Image") | |
) | |
demo.launch() |