Spaces:
Runtime error
Runtime error
| 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() | |