Spaces:
Runtime error
Runtime error
Download app.py from FENST4R/stable-diffusion-2-1-endpoint: direct link, hf CLI and curl.
- Browser
- Download file 531 Bytes
-
https://huggingface.co/spaces/FENST4R/stable-diffusion-2-1-endpoint/resolve/main/app.py
- Command line
-
hf download hf://spaces/FENST4R/stable-diffusion-2-1-endpoint/app.py
-
curl -L -o app.py https://huggingface.co/spaces/FENST4R/stable-diffusion-2-1-endpoint/resolve/main/app.py
531 Bytes
| 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() | |