A Python and Bash toolkit for interacting with the Black Forest Labs FLUX.1 Diffusion Model API
- Introduction
- Features
- Installation
- Configuration
- Usage
- Command-Line Arguments
- Examples
- Troubleshooting
- Contributing
- License
- Acknowledgements
- Contact
This Black Forest Labs FLUX.1 Diffusion Model Python Client is a Python script and macOS-specific Bash wrapper that facilitate easy interaction with the FLUX.1 Diffusion Model API as of September 2024. It allows users to input prompts directly from the clipboard, offers flexible seed value options, and provides verbose logging for better insights and debugging.
- Bash Wrapper (macOS Only): Use
pbpaste
to pipe clipboard content directly to the Python script. Ideal for macOS users who copy prompt text using Cmd-C. Simplifies usage with confirmation prompts and argument handling. - Flexible Seed Handling: Support for random, fixed, and null seed values.
- Verbose Mode: Enable detailed logging for debugging and insights.
- Currently, in the public specifications, the server does not return the seed used for image generation.
- Without knowing the seed, users cannot reproduce the same image by reusing the seed.
- Therefore, when
--seed rand
is used, the client generates and tracks its own seed to ensure reproducibility.
- Python 3: Ensure you have Python installed. Tested with Python 3.11.8.
- pip: Python package installer.
-
Clone the Repository
git clone https://github.com/yokoyama-flogics/flux-diffusion-client.git cd flux-diffusion-client
-
Install Dependencies
pip install -r requirements.txt
-
Make Bash Wrapper Executable
chmod +x gen_flux.sh
Create a .env
file in your home directory or the project root directory and add your FLUX.1 API key:
BFL_API_KEY=your_api_key_here
Ensure that the Python script (flux.py
) has access to the .env
file for loading environment variables.
You can run the Python script and provide the prompt via standard input:
echo "A beautiful sunset over the ocean." | python3 flux.py --width 800 --height 640
Output:
- Results are stored in the
output
directory in the current working directory. - If the
output
directory does not exist, it is created automatically. - Filenames include a timestamp followed by suffixes such as
_request.json
,_result.json
, and_result.jpg
.
The Bash wrapper simplifies usage by handling clipboard input and confirmation prompts. It is designed specifically for macOS.
./gen_flux.sh -wd 800 -ht 640
You will be prompted:
Are you sure you want to proceed? [y/N]:
./gen_flux.sh -y -wd 1024 -ht 768 --seed rand
./gen_flux.sh -h
This will display the help message from the Python script without prompting for confirmation.
Argument | Short | Description | Default |
---|---|---|---|
--width |
-wd |
Width of the image in pixels | 1024 |
--height |
-ht |
Height of the image in pixels | 1024 |
--variant |
-v |
Variant of the diffusion model | flux.1-pro |
--steps |
-s |
Number of network evaluations. Higher values improve quality but increase computation time. | 25 |
--prompt_upsampling |
-pu |
Enable prompt upsampling to improve image quality and fidelity to the prompt. | False |
--seed |
Fix the generation seed: provide an integer, rand to generate a random seed, or null to pass null. |
rand |
|
--guidance |
-g |
Guidance scale to control the fidelity and creativity of the generated image. Higher values adhere more strictly to the prompt. | 2.5 |
--safety_tolerance |
-st |
Safety tolerance to control the strictness of content filters. Lower values apply stricter filters. | 2 |
--interval |
-i |
Interval parameter to control how the diffusion model progresses during image generation. Smaller values result in more consistent and stable outputs, while larger values allow for more diversity. | 2.0 |
--verbose |
-V |
Enable verbose output for request and result details. | False |
Argument | Short | Description |
---|---|---|
--yes |
-y |
Proceed without confirmation prompt. |
--help |
-h |
Display help message. |
Other arguments | Passed directly to the Python script (flux.py ). |
echo "A serene lake surrounded by mountains during sunrise." | python3 flux.py -wd 800 -ht 640
./gen_flux.sh -wd 800 -ht 640
You will be prompted:
Are you sure you want to proceed? [y/N]:
./gen_flux.sh -y --seed rand -wd 1024 -ht 768
./gen_flux.sh -y --seed 123456789 -wd 800 -ht 640
./gen_flux.sh -y --seed null -wd 800 -ht 640
./gen_flux.sh -h
This will display the help information from flux.py
without prompting for confirmation.
Issue:
Error: BFL_API_KEY not found in environment variables.
Solution:
- Ensure that the
.env
file is present in your home directory or the project root. - Verify that
BFL_API_KEY
is correctly set in the.env
file.
Issue:
Error: --seed must be an integer, 'rand', or 'null'.
Solution:
- Provide a valid seed value:
- An integer (e.g.,
--seed 123456789
) rand
to generate a random seed (e.g.,--seed rand
)null
to pass null as the seed (e.g.,--seed null
)
- An integer (e.g.,
Issue:
Errors during pip install -r requirements.txt
Solution:
- Ensure you are using the correct Python version.
- Check for any network issues or permission errors.
Contributions are welcome! Please follow these steps to contribute:
-
Fork the Repository
- Click the "Fork" button on the repository page.
-
Clone Your Fork
git clone https://github.com/yokoyama-flogics/flux-diffusion-client.git cd flux-diffusion-client
-
Create a New Branch
git checkout -b feature/your-feature-name
-
Make Your Changes
- Implement your feature or fix.
-
Commit Your Changes
git commit -m "Add feature: your feature description"
-
Push to Your Fork
git push origin feature/your-feature-name
-
Create a Pull Request
- Go to the original repository and click "New Pull Request".
This project is licensed under the BSD 2-Clause License.
- GitHub: black-forest-labs/flux: Official inference repo for FLUX.1 models)
For any questions or support, please reach out to flogics.com.