rvienne commited on
Commit
6d11a96
·
1 Parent(s): 7890df2

added dumpy

Browse files
Files changed (1) hide show
  1. dumpy.py +52 -0
dumpy.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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:
31
+ if response.user_id not in output:
32
+ output[response.user_id] = 0
33
+ output[response.user_id] += 1
34
+
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! ***")