-
Notifications
You must be signed in to change notification settings - Fork 2
/
sync-model.py
39 lines (30 loc) · 1.03 KB
/
sync-model.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
import json
import urllib.request
import urllib.parse
def read_and_serialize_json(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
return data
def get_huggingface_models(repo_id):
url = f"https://huggingface.co/api/models/{repo_id}"
with urllib.request.urlopen(url) as response:
response_data = response.read()
response_json = json.loads(response_data)
return response_json
file_path = './index.json'
indexs = read_and_serialize_json(file_path)
i = 0
total = len(indexs)
for index in indexs:
print(f"index {i}/{total}")
if index['model_type']=='instruct' or index['model_type']=='chat':
try:
remote_index = get_huggingface_models(index['id'])
index['like_count'] = remote_index['likes']
index['download_count'] = remote_index['downloads']
except Exception as e:
pass
i+=1
text = json.dumps(indexs,indent=4)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(text)