-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_extract.py
51 lines (41 loc) · 1.81 KB
/
json_extract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import json
def find_filepath_by_hash(hash_value, data):
for filepath, hashes in data.items():
print(f"{filepath}{hashes}{hash_value}")
for key, value in hashes.items():
if hash_value == value:
print(f"found hash {hash_value} in {key}. Lora is {hashes['name']}. trained words are {hashes['trainedWords']} ")
return hashes['name']
return None
def getlorahashes(foldertosearch):
res = {}
for root, dirs, files in os.walk(foldertosearch):
for filename in files:
if '.civitai.info' in filename:
fullfilepath = os.path.join(root,filename)
with open(fullfilepath, 'r', encoding='utf-8') as file:
json_data = json.load(file)
if '.civitai.info' in filename:
test = json_data['files']
for each in test:
hashes = each['hashes']
res[fullfilepath] = {
'name': json_data.get('model',None).get('name',None),
'trainedWords': json_data.get("trainedWords", None),
'AutoV2': hashes.get('AutoV2', None),
'SHA256': hashes.get('SHA256', None),
'CRC32': hashes.get('CRC32', None),
'BLAKE3': hashes.get('BLAKE3', None)
}
print(str(hashes))
print("Done")
return res
res1 = {}
dir1 = 'X:/dif/stable-diffusion-webui-docker/data/embeddings'
res1.update(getlorahashes(dir1))
dir2 = 'X:/dif/stable-diffusion-webui-docker/data/models/Lora'
res1.update(getlorahashes(dir2))
thingy = find_filepath_by_hash('A0BAC10CA3',res1)
print(thingy)
print("test")