Spaces:
Runtime error
Runtime error
File size: 531 Bytes
d79f80b 2179156 d79f80b 2179156 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
model_id = "stabilityai/stable-diffusion-2-1"
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.float16 if device == "cuda" else torch.float32
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype)
pipe = pipe.to(device)
def generate(prompt):
image = pipe(prompt).images[0]
return image
demo = gr.Interface(fn=generate, inputs="text", outputs="image")
if __name__ == "__main__":
demo.launch()
|