LTEnjoy commited on
Commit
874c79e
·
verified ·
1 Parent(s): 4675c91

Update loop_retrieve_cards.py

Browse files
Files changed (1) hide show
  1. 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
- new_models = fetch_models()
35
- new_datasets = fetch_datasets()
36
-
37
- # Add READMEs
38
- new_readme_dict = {}
39
- for model in new_models:
40
- new_readme_dict[model] = fetch_readme(model, "model")
41
-
42
- for dataset in new_datasets:
43
- new_readme_dict[dataset] = fetch_readme(dataset, "dataset")
44
-
45
- # Update global variables
46
- models = new_models
47
- datasets = new_datasets
48
- readme_dict = new_readme_dict
49
-
50
-
51
- t = threading.Thread(target=run)
52
- t.start()
 
 
 
 
 
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()