Download app.py from blinklink/T2I: direct link, hf CLI and curl.
- Browser
- Download file 732 Bytes
-
https://huggingface.co/spaces/blinklink/T2I/resolve/main/app.py
- Command line
-
hf download hf://spaces/blinklink/T2I/app.py
-
curl -L -o app.py https://huggingface.co/spaces/blinklink/T2I/resolve/main/app.py
732 Bytes
| import gradio as gr | |
| import torch | |
| from diffusers import StableDiffusionPipeline | |
| model_name = "runwayml/stable-diffusion-v1-5" | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| if device == "cuda": | |
| pipe = StableDiffusionPipeline.from_pretrained(model_name, torch_dtype=torch.float16).to(device) | |
| else: | |
| pipe = StableDiffusionPipeline.from_pretrained(model_name).to(device) | |
| def generate_image(prompt): | |
| with torch.no_grad(): | |
| image = pipe(prompt, num_inference_steps=50, guidance_scale=9.5).images[0] | |
| return image | |
| iface = gr.Interface( | |
| fn=generate_image, | |
| inputs="text", | |
| outputs="image", | |
| title="BL's T2I Generator", | |
| description="Enter a prompt to generate an image." | |
| ) | |
| iface.launch() | |