CivArchive
    ← All articles
    Published October 18, 2023by smokescreen

    Simple script to make a wildcard file from your textual inversions

    1.7K views0 reactions3 comments on CivitAI12 collected
    tool guidewildcards

    This lets you specify a directory and everything gets put one-per-line into a text file you name. It's an easy way to randomly select from all your person embeddings with an extension like Dynamic Prompts or Wildcards. Code below, could not attach without triggering a Civitai.com bug. Save it to a file, I recommend 'collect_embeddings.py'. If you run the file on the command line ('python collect_embeddings.py') it will tell you how to use it.

    ```

    import os

    import sys

    from pathlib import Path

    def list_files(directory, output_file, extension):

    with open(output_file, 'w') as f:

    for filename in os.listdir(directory):

    file_path = Path(filename)

    if file_path.suffix == extension:

    f.write(f'{file_path.stem}\n')

    if name == "__main__":

    if len(sys.argv) != 4:

    print("Usage: python collect_embeddings.py <directory = embeddings> <output_file = embeddings.txt> <extension = .pt>")

    sys.exit(1)

    directory = sys.argv[1]

    list_files(directory, sys.argv[2], sys.argv[3])

    ```