alvarobartt HF staff commited on
Commit
60b6414
β€’
1 Parent(s): b43278c

Create dump.py

Browse files
Files changed (1) hide show
  1. dump.py +36 -0
dump.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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:
23
+ if response.user_id not in output:
24
+ output[response.user_id] = 0
25
+ output[response.user_id] += 1
26
+
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.dumps(output, indent=4),
33
+ path_in_repo="stats.json",
34
+ repo_id="DIBT/prompt-collective-dashboard",
35
+ repo_type="space",
36
+ )