Spaces:
Runtime error
Runtime error
Commit
•
6106c50
1
Parent(s):
60b6414
Update dump.py
Browse files
dump.py
CHANGED
@@ -1,22 +1,30 @@
|
|
1 |
import json
|
|
|
2 |
import os
|
3 |
|
4 |
import argilla as rg
|
5 |
from huggingface_hub import HfApi
|
6 |
|
|
|
|
|
|
|
7 |
if __name__ == "__main__":
|
|
|
8 |
rg.init(
|
9 |
api_url=os.getenv("ARGILLA_API_URL"),
|
10 |
api_key=os.getenv("ARGILLA_API_KEY"),
|
11 |
extra_headers={"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"},
|
12 |
)
|
13 |
|
|
|
14 |
dataset = rg.FeedbackDataset.from_argilla(
|
15 |
os.getenv("SOURCE_DATASET"),
|
16 |
workspace=os.getenv("SOURCE_WORKSPACE"),
|
17 |
)
|
|
|
18 |
dataset = dataset.filter_by(response_status=["submitted"]) # type: ignore
|
19 |
|
|
|
20 |
output = {}
|
21 |
for record in dataset.records:
|
22 |
for response in record.responses:
|
@@ -27,10 +35,18 @@ if __name__ == "__main__":
|
|
27 |
for key in list(output.keys()):
|
28 |
output[rg.User.from_id(key).username] = output.pop(key)
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
api = HfApi(token=os.getenv("HF_TOKEN"))
|
31 |
api.upload_file(
|
32 |
-
path_or_fileobj=json
|
33 |
path_in_repo="stats.json",
|
34 |
repo_id="DIBT/prompt-collective-dashboard",
|
35 |
repo_type="space",
|
36 |
)
|
|
|
|
1 |
import json
|
2 |
+
import logging
|
3 |
import os
|
4 |
|
5 |
import argilla as rg
|
6 |
from huggingface_hub import HfApi
|
7 |
|
8 |
+
logger = logging.getLogger(__name__)
|
9 |
+
logger.setLevel(logging.INFO)
|
10 |
+
|
11 |
if __name__ == "__main__":
|
12 |
+
logger.info("*** Initializing Argilla session ***")
|
13 |
rg.init(
|
14 |
api_url=os.getenv("ARGILLA_API_URL"),
|
15 |
api_key=os.getenv("ARGILLA_API_KEY"),
|
16 |
extra_headers={"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"},
|
17 |
)
|
18 |
|
19 |
+
logger.info("*** Fetching dataset from Argilla ***")
|
20 |
dataset = rg.FeedbackDataset.from_argilla(
|
21 |
os.getenv("SOURCE_DATASET"),
|
22 |
workspace=os.getenv("SOURCE_WORKSPACE"),
|
23 |
)
|
24 |
+
logger.info("*** Filtering records by `response_status` ***")
|
25 |
dataset = dataset.filter_by(response_status=["submitted"]) # type: ignore
|
26 |
|
27 |
+
logger.info("*** Calculating users and annotation count ***")
|
28 |
output = {}
|
29 |
for record in dataset.records:
|
30 |
for response in record.responses:
|
|
|
35 |
for key in list(output.keys()):
|
36 |
output[rg.User.from_id(key).username] = output.pop(key)
|
37 |
|
38 |
+
logger.info("*** Users and annotation count successfully calculated! ***")
|
39 |
+
|
40 |
+
logger.info("*** Dumping Python dict into `stats.json` ***")
|
41 |
+
with open("stats.json", "w") as file:
|
42 |
+
json.dump(output, file, indent=4)
|
43 |
+
|
44 |
+
logger.info("*** Uploading `stats.json` to Hugging Face Hub ***")
|
45 |
api = HfApi(token=os.getenv("HF_TOKEN"))
|
46 |
api.upload_file(
|
47 |
+
path_or_fileobj="stats.json",
|
48 |
path_in_repo="stats.json",
|
49 |
repo_id="DIBT/prompt-collective-dashboard",
|
50 |
repo_type="space",
|
51 |
)
|
52 |
+
logger.info("*** `stats.json` successfully uploaded to Hugging Face Hub! ***")
|