Spaces:
Running
Running
Update loop_retrieve_cards.py
Browse files- loop_retrieve_cards.py +56 -52
loop_retrieve_cards.py
CHANGED
@@ -1,52 +1,56 @@
|
|
1 |
-
import threading
|
2 |
-
import time
|
3 |
-
|
4 |
-
from utils import fetch_models, fetch_datasets, fetch_readme
|
5 |
-
from tqdm import tqdm
|
6 |
-
|
7 |
-
|
8 |
-
# Define global variables
|
9 |
-
models = None
|
10 |
-
datasets = None
|
11 |
-
readme_dict = {}
|
12 |
-
|
13 |
-
|
14 |
-
# Provide an API to get models
|
15 |
-
def get_models():
|
16 |
-
return models
|
17 |
-
|
18 |
-
|
19 |
-
# Provide an API to get datasets
|
20 |
-
def get_datasets():
|
21 |
-
return datasets
|
22 |
-
|
23 |
-
|
24 |
-
# Provide an API to get READMEs
|
25 |
-
def get_readme_dict():
|
26 |
-
return readme_dict
|
27 |
-
|
28 |
-
|
29 |
-
# Start a thread to continuously update cards
|
30 |
-
def run():
|
31 |
-
global models, datasets, readme_dict, cnt
|
32 |
-
|
33 |
-
while True:
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
import threading
|
2 |
+
import time
|
3 |
+
|
4 |
+
from utils import fetch_models, fetch_datasets, fetch_readme
|
5 |
+
from tqdm import tqdm
|
6 |
+
|
7 |
+
|
8 |
+
# Define global variables
|
9 |
+
models = None
|
10 |
+
datasets = None
|
11 |
+
readme_dict = {}
|
12 |
+
|
13 |
+
|
14 |
+
# Provide an API to get models
|
15 |
+
def get_models():
|
16 |
+
return models
|
17 |
+
|
18 |
+
|
19 |
+
# Provide an API to get datasets
|
20 |
+
def get_datasets():
|
21 |
+
return datasets
|
22 |
+
|
23 |
+
|
24 |
+
# Provide an API to get READMEs
|
25 |
+
def get_readme_dict():
|
26 |
+
return readme_dict
|
27 |
+
|
28 |
+
|
29 |
+
# Start a thread to continuously update cards
|
30 |
+
def run():
|
31 |
+
global models, datasets, readme_dict, cnt
|
32 |
+
|
33 |
+
while True:
|
34 |
+
try:
|
35 |
+
new_models = fetch_models()
|
36 |
+
new_datasets = fetch_datasets()
|
37 |
+
|
38 |
+
# Add READMEs
|
39 |
+
new_readme_dict = {}
|
40 |
+
for model in new_models:
|
41 |
+
new_readme_dict[model] = fetch_readme(model, "model")
|
42 |
+
|
43 |
+
for dataset in new_datasets:
|
44 |
+
new_readme_dict[dataset] = fetch_readme(dataset, "dataset")
|
45 |
+
|
46 |
+
# Update global variables
|
47 |
+
models = new_models
|
48 |
+
datasets = new_datasets
|
49 |
+
readme_dict = new_readme_dict
|
50 |
+
|
51 |
+
except Exception as e:
|
52 |
+
print(e)
|
53 |
+
|
54 |
+
|
55 |
+
t = threading.Thread(target=run)
|
56 |
+
t.start()
|