coderdecoder01 commited on
Commit
db5e52c
·
verified ·
1 Parent(s): 754fb9f

Add script to make repo public

Browse files
Files changed (1) hide show
  1. fix_visibility.py +48 -0
fix_visibility.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Make the invitation dataset repo public so the MP4 link works without login."""
2
+ import os
3
+ import requests
4
+ from huggingface_hub import HfApi
5
+
6
+ R = "coderdecoder01/retirement-invitation-mamta"
7
+ t = os.environ["HF_TOKEN"]
8
+ h = {"Authorization": "Bearer " + t}
9
+ api = HfApi()
10
+
11
+
12
+ def vis(repo=R):
13
+ try:
14
+ r = requests.get("https://huggingface.co/api/datasets/" + repo, headers=h, timeout=60)
15
+ return r.json().get("private")
16
+ except Exception as e:
17
+ return "? %s" % repr(e)[:80]
18
+
19
+
20
+ print("before:", vis(), flush=True)
21
+
22
+ try:
23
+ api.update_repo_settings(repo_id=R, repo_type="dataset", private=False)
24
+ print("update_repo_settings: OK", flush=True)
25
+ except Exception as e:
26
+ print("update_repo_settings FAIL:", repr(e)[:300], flush=True)
27
+
28
+ print("after1:", vis(), flush=True)
29
+
30
+ if vis() is not False:
31
+ r = requests.patch("https://huggingface.co/api/datasets/%s/settings" % R, headers=h,
32
+ json={"private": False}, timeout=60)
33
+ print("PATCH /settings:", r.status_code, r.text[:300], flush=True)
34
+ print("after2:", vis(), flush=True)
35
+
36
+ if vis() is not False:
37
+ r = requests.post("https://huggingface.co/api/datasets/%s/settings" % R, headers=h,
38
+ json={"private": False}, timeout=60)
39
+ print("POST /settings:", r.status_code, r.text[:300], flush=True)
40
+ print("after3:", vis(), flush=True)
41
+
42
+ if vis() is not False:
43
+ try:
44
+ api.create_repo(repo_id="coderdecoder01/retirement-invite-mamta-public", repo_type="dataset",
45
+ private=False, exist_ok=True)
46
+ print("new repo private:", vis("coderdecoder01/retirement-invite-mamta-public"), flush=True)
47
+ except Exception as e:
48
+ print("create public repo FAIL:", repr(e)[:300], flush=True)