|
import argparse |
|
import json |
|
import os |
|
import shutil |
|
|
|
def move_non_lora_safetensors(src_dir, dest_dir): |
|
for file in os.listdir(src_dir): |
|
if file.endswith(".json"): |
|
try: |
|
with open(os.path.join(src_dir, file), 'r', encoding='utf-8') as f: |
|
data = json.load(f) |
|
if data.get("__metadata__", {}).get("ss_network_module") != "networks.lora": |
|
safetensors_file = file.replace(".json", ".safetensors") |
|
src_path = os.path.join(src_dir, safetensors_file) |
|
dest_path = os.path.join(dest_dir, safetensors_file) |
|
if os.path.isfile(src_path): |
|
shutil.move(src_path, dest_path) |
|
except json.JSONDecodeError: |
|
continue |
|
|
|
if __name__ == "__main__": |
|
parser = argparse.ArgumentParser(description="Move .safetensors files of non-networks.lora JSON content.") |
|
parser.add_argument("src_dir", help="Source directory containing .json and .safetensors files.") |
|
parser.add_argument("dest_dir", help="Destination directory for non-networks.lora .safetensors files.") |
|
args = parser.parse_args() |
|
|
|
move_non_lora_safetensors(args.src_dir, args.dest_dir) |
|
|