Spaces:
Runtime error
Runtime error
File size: 548 Bytes
de54060 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import gradio as gr
from diffusers import StableDiffusionPipeline
import torch, os
pipe = StableDiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-2",
torch_dtype=torch.float16,
).to("cuda" if torch.cuda.is_available() else "cpu")
def generate(prompt):
image = pipe(prompt, num_inference_steps=25).images[0]
return image
demo = gr.Interface(
fn=generate,
inputs=gr.Textbox(label="Prompt"),
outputs=gr.Image(type="pil"),
title="Stable Diffusion Demo",
)
if __name__ == "__main__":
demo.launch()
|