Spaces:
Runtime error
Runtime error
Download utils/text2image.py from DmitrMakeev/Diffusion-API: direct link, hf CLI and curl.
- Browser
- Download file 810 Bytes
-
https://huggingface.co/spaces/DmitrMakeev/Diffusion-API/resolve/2204ef0c21d00ef5dd0b19c6277f1e0a3ec139dd/utils/text2image.py
- Command line
-
hf download hf://spaces/DmitrMakeev/Diffusion-API@2204ef0c21d00ef5dd0b19c6277f1e0a3ec139dd/utils/text2image.py
-
curl -L -o text2image.py https://huggingface.co/spaces/DmitrMakeev/Diffusion-API/resolve/2204ef0c21d00ef5dd0b19c6277f1e0a3ec139dd/utils/text2image.py
810 Bytes
| from diffusers import StableDiffusionPipeline, DDIMScheduler | |
| import torch | |
| def stable_diffusion_text2img( | |
| model_path:str, | |
| prompt:str, | |
| negative_prompt:str, | |
| guidance_scale:int, | |
| num_inference_step:int, | |
| height:int, | |
| width:int, | |
| ): | |
| pipe = StableDiffusionPipeline.from_pretrained( | |
| model_path, | |
| safety_checker=None, | |
| torch_dtype=torch.float16 | |
| ).to("cuda") | |
| pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config) | |
| pipe.enable_xformers_memory_efficient_attention() | |
| images = pipe( | |
| prompt, | |
| height=height, | |
| width=width, | |
| negative_prompt=negative_prompt, | |
| num_images_per_prompt=1, | |
| num_inference_steps=num_inference_step, | |
| guidance_scale=guidance_scale, | |
| ).images | |
| return images | |