Create yaml wildcard from loras directory

Create yaml wildcard from loras directory
Step-by-Step Usage:
Download the python file where you want
If it is the by_filename
In the Stable Diffusion parameters change refer to Lora by Filename. By this way there is no chance to encounter lora name errors !
Running Time:
Execute with:
python loras_to_yaml_wildcard.py OR python loras_to_yaml_wildcard_by_filename.pyChoose the directory with the loras inside (a directory with subdirectory, see the example)
Running a second time:
Same running time but you can use the precedent path to the loras directory
Specifications:
If there is a ".json" file associates with the lora, the positive prompt and the weight are taken from this one.
By default the positive prompt is "" and the weight is 1.
Concerning a possible rename, the name of activation is taken in the ".civitai.info" file if it exists.
By the way, a weight of 0 is set automatically to 1.
Example:
Suppose you have the following directory structure:
Lora/
├── characters
| ├── lora1.safetensors
| └── lora2.safetensors
├── positions
| ├── lora1.safetensors
| └── lora2.safetensors
├── styles
| └── lora.safetensors
└── sliders
├── lora1.safetensors
└── lora2.safetensorsThe output loras.yaml will produce a YAML file structured like this: (the bracket doesn't exist)
loras:
characters:
- <lora:{lora_name}:{weight}> {positive_prompt}
- <lora:{lora_name}:{weight}> {positive_prompt}
positions:
- <lora:{lora_name}:{weight}> {positive_prompt}
styles:
- <lora:{lora_name}:{weight}> {positive_prompt}
- <lora:{lora_name}:{weight}> {positive_prompt}
sliders
- <lora:{lora_name}:{weight}> {positive_prompt}Troubleshooting:
Ensure that all required libraries (
pyyaml,tqdm, andtkinter) are installed. You can install any missing libraries usingpip.If you encounter issues, try running the script with administrative privileges to ensure it has the necessary permissions to read and write files.