Last active
November 20, 2023 21:11
-
-
Save catboxanon/4f56fdd1dd0ab207c6231eef3006c012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from pathlib import Path | |
from glob import glob | |
from contextlib import redirect_stdout | |
from io import StringIO | |
from tqdm import tqdm | |
import modules.hashes | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-p', '--path', type=str, required=True) | |
parser.add_argument('-t', '--type', type=str, required=True, choices=['checkpoint', 'hypernet', 'textual_inversion', 'lora']) | |
args = parser.parse_args() | |
class NullIO(StringIO): | |
def write(self, txt): | |
pass | |
def silent(fn): | |
def silent_fn(*args, **kwargs): | |
with redirect_stdout(NullIO()): | |
return fn(*args, **kwargs) | |
return silent_fn | |
silent_sha256 = silent(modules.hashes.sha256) | |
if __name__ == '__main__': | |
for file in tqdm([Path(f) for f in list(glob(str(Path(args.path)) + '/**/*', recursive=True)) if Path(f).is_file() and Path(f).suffix in ['.ckpt', '.safetensors', '.pt']]): | |
if ( | |
(args.type == 'checkpoint' and file.suffix in ['.ckpt', '.safetensors']) | |
or (args.type == 'hypernet' and file.suffix in ['.pt']) | |
or (args.type == 'textual_inversion' and file.suffix in ['.pt', '.png']) | |
or (args.type == 'lora' and file.suffix in ['.safetensors']) | |
): | |
title = f'{args.type}/{file.stem if args.type not in ["checkpoint"] else file.name}' | |
silent_sha256(str(file), title, use_addnet_hash=True if args.type in ['lora'] else False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: Requires the
IGNORE_CMD_ARGS_ERRORS
env var to be set to any value (i.e.1
orTrue
). I would also recommend running this in a fresh terminal session so the environment isn't polluted bywebui.bat
env vars.