Generate character consistent images with a single reference
86
stars
5
commits
Python
primary language
Jun 27, 2025
updated
Train character LoRAs from a single reference image and generate character consistent images across diverse scenes.
Clone the repository:
git clone https://github.com/RishiDesai/CharForge.git
cd CharForge
Set these API keys and variables in your .env and add funds where appropriate
HF_TOKEN
HF_HOME
CIVITAI_API_KEY
TOGETHER_API_KEY
FAL_KEY
OPENAI_API_KEY
Log into Hugging Face and accept their terms of service to download Flux.1-dev
Run the setup script
bash setup.sh
This will:
Install submodules including ComfyUI, all required ComfyUI custom nodes, LoRACaptioner, MVAdapter, and ai-toolkit.
Download all necessary models to HF_HOME
Set up the character sheet generation pipeline
Activate venv
source .venv/bin/activate
python train_character.py --name "character_name" --input "path/to/reference_image.png"
python train_character.py \
--name "character_name" \
--input "path/to/reference_image.png" \
[--work_dir WORK_DIR] \
[--steps STEPS] \
[--batch_size BATCH_SIZE] \
[--lr LEARNING_RATE] \
[--train_dim TRAIN_DIM] \
[--rank_dim RANK_DIM] \
[--pulidflux_images PULID_FLUX_IMAGES]
--name (str): Character name (used for folder and model naming)--input (str): Path to input image--work_dir (str, optional): Working directory (defaults to ./scratch/{name}/)--steps (int, optional): Number of training steps (default: 800)--batch_size (int, optional): Training batch size (default: 1)--lr (float, optional): Learning rate (default: 8e-4)--train_dim (int, optional): Training image dimension (default: 512)--rank_dim (int, optional): LoRA rank dimension (default: 8)--pulidflux_images (int, optional): Number of Pulid-Flux images to include (default: 0)This command will:
python test_character.py --character_name "character_name" --prompt "A detailed prompt here"
python test_character.py \
--character_name "character_name" \
--prompt "A detailed prompt here" \
[--work_dir WORK_DIR] \
[--lora_weight LORA_WEIGHT] \
[--test_dim TEST_DIM] \
[--do_optimize_prompt/--no_optimize_prompt] \
[--output_filenames FILE1 FILE2 ...] \
[--batch_size BATCH_SIZE] \
[--num_inference_steps STEPS] \
[--fix_outfit/--no_fix_outfit] \
[--safety_check/--no_safety_check] \
[--face_enhance/--no_face_enhance]
--character_name (str): Name of the character (used to find LoRA and work_dir)--prompt (str): The prompt to use for generation--work_dir (str, optional): Working directory (defaults to ./scratch/{character_name}/)--lora_weight (float, optional): LoRA strength (default: 0.73)--test_dim (int, optional): Image width/height (default: 1024)--do_optimize_prompt / --no_optimize_prompt: Whether to optimize the prompt using LoRACaptioner (default: enabled)--output_filenames (str, optional): Filenames for output images (space separated list)--batch_size (int, optional): Number of images to generate (default: 4)--num_inference_steps (int, optional): Steps for generation (default: 30)--fix_outfit / --no_fix_outfit: Use the reference image flag in prompt optimization (default: disabled)--safety_check / --no_safety_check: Run safety checks on generated images (default: enabled)--face_enhance / --no_face_enhance: Enable or disable face enhancement (default: disabled)This command will:
Note: The first run of train_character.py and test_character.py will take longer as remaining models will be downloaded.
./scratch/{character_name} for easy access and organization.train_character.py, or by editing the YAML config scripts/character_lora.yaml.python scripts/serve_lora.py to serve LoRA weights via a FastAPI server, making them publicly accessible (e.g., for fal.ai inference).python scripts/run_comfy.py to launch a ComfyUI server, useful for doing inference manually.bash scripts/symlink_loras.sh to symlink trained LoRA weights from scratch/{character_name}/ to the ComfyUI LoRA directory for easy access.batch_size=1 for GPUs with less than 48GB VRAM5 commits
Python
96.2%
Shell
3.8%
Generate character consistent images with a single reference
86
stars
5
commits
Python
primary language
Jun 27, 2025
updated
Train character LoRAs from a single reference image and generate character consistent images across diverse scenes.
Clone the repository:
git clone https://github.com/RishiDesai/CharForge.git
cd CharForge
Set these API keys and variables in your .env and add funds where appropriate
HF_TOKEN
HF_HOME
CIVITAI_API_KEY
TOGETHER_API_KEY
FAL_KEY
OPENAI_API_KEY
Log into Hugging Face and accept their terms of service to download Flux.1-dev
Run the setup script
bash setup.sh
This will:
Install submodules including ComfyUI, all required ComfyUI custom nodes, LoRACaptioner, MVAdapter, and ai-toolkit.
Download all necessary models to HF_HOME
Set up the character sheet generation pipeline
Activate venv
source .venv/bin/activate
python train_character.py --name "character_name" --input "path/to/reference_image.png"
python train_character.py \
--name "character_name" \
--input "path/to/reference_image.png" \
[--work_dir WORK_DIR] \
[--steps STEPS] \
[--batch_size BATCH_SIZE] \
[--lr LEARNING_RATE] \
[--train_dim TRAIN_DIM] \
[--rank_dim RANK_DIM] \
[--pulidflux_images PULID_FLUX_IMAGES]
--name (str): Character name (used for folder and model naming)--input (str): Path to input image--work_dir (str, optional): Working directory (defaults to ./scratch/{name}/)--steps (int, optional): Number of training steps (default: 800)--batch_size (int, optional): Training batch size (default: 1)--lr (float, optional): Learning rate (default: 8e-4)--train_dim (int, optional): Training image dimension (default: 512)--rank_dim (int, optional): LoRA rank dimension (default: 8)--pulidflux_images (int, optional): Number of Pulid-Flux images to include (default: 0)This command will:
python test_character.py --character_name "character_name" --prompt "A detailed prompt here"
python test_character.py \
--character_name "character_name" \
--prompt "A detailed prompt here" \
[--work_dir WORK_DIR] \
[--lora_weight LORA_WEIGHT] \
[--test_dim TEST_DIM] \
[--do_optimize_prompt/--no_optimize_prompt] \
[--output_filenames FILE1 FILE2 ...] \
[--batch_size BATCH_SIZE] \
[--num_inference_steps STEPS] \
[--fix_outfit/--no_fix_outfit] \
[--safety_check/--no_safety_check] \
[--face_enhance/--no_face_enhance]
--character_name (str): Name of the character (used to find LoRA and work_dir)--prompt (str): The prompt to use for generation--work_dir (str, optional): Working directory (defaults to ./scratch/{character_name}/)--lora_weight (float, optional): LoRA strength (default: 0.73)--test_dim (int, optional): Image width/height (default: 1024)--do_optimize_prompt / --no_optimize_prompt: Whether to optimize the prompt using LoRACaptioner (default: enabled)--output_filenames (str, optional): Filenames for output images (space separated list)--batch_size (int, optional): Number of images to generate (default: 4)--num_inference_steps (int, optional): Steps for generation (default: 30)--fix_outfit / --no_fix_outfit: Use the reference image flag in prompt optimization (default: disabled)--safety_check / --no_safety_check: Run safety checks on generated images (default: enabled)--face_enhance / --no_face_enhance: Enable or disable face enhancement (default: disabled)This command will:
Note: The first run of train_character.py and test_character.py will take longer as remaining models will be downloaded.
./scratch/{character_name} for easy access and organization.train_character.py, or by editing the YAML config scripts/character_lora.yaml.python scripts/serve_lora.py to serve LoRA weights via a FastAPI server, making them publicly accessible (e.g., for fal.ai inference).python scripts/run_comfy.py to launch a ComfyUI server, useful for doing inference manually.bash scripts/symlink_loras.sh to symlink trained LoRA weights from scratch/{character_name}/ to the ComfyUI LoRA directory for easy access.batch_size=1 for GPUs with less than 48GB VRAM5 commits
Python
96.2%
Shell
3.8%