Spaces:
Sleeping
Sleeping
Download app.py from groslead/image-generator-api: direct link, hf CLI and curl.
- Browser
- Download file 633 Bytes
-
https://huggingface.co/spaces/groslead/image-generator-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/groslead/image-generator-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/groslead/image-generator-api/resolve/main/app.py
633 Bytes
| import gradio as gr | |
| from diffusers import StableDiffusionPipeline | |
| import torch | |
| model_id = "stabilityai/sd-turbo" | |
| pipe = StableDiffusionPipeline.from_pretrained( | |
| model_id, | |
| torch_dtype=torch.float32 | |
| ) | |
| pipe = pipe.to("cpu") | |
| pipe.enable_attention_slicing() | |
| pipe.enable_vae_slicing() | |
| torch.set_float32_matmul_precision("high") | |
| def generate(prompt): | |
| image = pipe( | |
| prompt, | |
| height=240, | |
| width=240, | |
| num_inference_steps=4, | |
| guidance_scale=0.0 | |
| ).images[0] | |
| return image | |
| gr.Interface( | |
| fn=generate, | |
| inputs=gr.Textbox(label="Prompt"), | |
| outputs=gr.Image(type="pil") | |
| ).launch() | |