Perfect your image generation prompt with a visual LLM.
Works best to improve adherence to complex prompts.
Install this tool using pip
or pipx
:
pip install perfect-prompt
Optional: to run image generation locally, you will also need to install ComfyUI with FLUX.1-dev.
Basic usage:
perfect-prompt "A robot holding a bouquet of sunflowers, standing in front of a crumbling brick wall covered in graffiti." -o images -n 3 --comfy-output-dir="C:\ComfyUI_windows_portable\ComfyUI\output"
This will generate 3 images attempting to adhere to this prompt within ./images
.
By default, perfect-prompt uses local models. You can configure this behavior with flags. For example, here is a version of the above prompt that uses models via API:
perfect-prompt "A robot holding a bouquet of sunflowers, standing in front of a crumbling brick wall covered in graffiti." -o images -n 3 --refine-model=pixtral-large --gen-model=flux-dev
And here is the resulting sequence of images:
Since this uses APIs, you'll to set need keys in your environment:
LLM_MISTRAL_KEY=<your key from https://console.mistral.ai/>
BFL_API_KEY=<your key from https://docs.bfl.ml/>
Many models are available for --refine-model
via Simon Willison’s llm
package, for example:
gpt-4o (uses OPENAI_API_KEY)
gpt-4o-mini (uses OPENAI_API_KEY)
pixtral-12b (uses LLM_MISTRAL_KEY)
pixtral-large (uses LLM_MISTRAL_KEY)
gemini-1.5-pro-latest (uses LLM_GEMINI_KEY)
gemini-1.5-flash-latest (uses LLM_GEMINI_KEY)
For help, run:
perfect-prompt --help
You can also use:
python -m perfect_prompt --help
To contribute to this tool, use uv. The following command will establish the venv and run tests:
uv run pytest
To run perfect-prompt locally, use:
uv run perfect-prompt