Spaces:
Build error
Build error
Download flux-cpu.py from aliasystems/README: direct link, hf CLI and curl.
- Browser
- Download file 943 Bytes
-
https://huggingface.co/spaces/aliasystems/README/resolve/main/flux-cpu.py
- Command line
-
hf download hf://spaces/aliasystems/README/flux-cpu.py
-
curl -L -o flux-cpu.py https://huggingface.co/spaces/aliasystems/README/resolve/main/flux-cpu.py
943 Bytes
| from dotenv import load_dotenv | |
| import os | |
| os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" | |
| load_dotenv() # Load the environment variables from .env | |
| # Access the token | |
| access_token = os.getenv("HUGGING_FACE_HUB_TOKEN") | |
| import torch | |
| from diffusers import FluxPipeline | |
| # Enable CPU offloading before loading the model | |
| # FluxPipeline.enable_model_cpu_offload() | |
| # pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16) | |
| pipe = FluxPipeline.from_pretrained( | |
| "black-forest-labs/FLUX.1-dev", | |
| torch_dtype=torch.bfloat16, | |
| device_map="balanced") | |
| prompt = "A homeless cat holding a sign which says, 'Will Youtube for Food'" | |
| image = pipe( | |
| prompt, | |
| height=1024, | |
| width=1024, | |
| guidance_scale=3.5, | |
| num_inference_steps=50, | |
| max_sequence_length=512, | |
| generator=torch.Generator("cpu").manual_seed(0) | |
| ).images[0] | |
| image.save("fluxpng.dev") | |