File size: 1,745 Bytes
db5e52c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Make the invitation dataset repo public so the MP4 link works without login."""
import os
import requests
from huggingface_hub import HfApi

R = "coderdecoder01/retirement-invitation-mamta"
t = os.environ["HF_TOKEN"]
h = {"Authorization": "Bearer " + t}
api = HfApi()


def vis(repo=R):
    try:
        r = requests.get("https://huggingface.co/api/datasets/" + repo, headers=h, timeout=60)
        return r.json().get("private")
    except Exception as e:
        return "? %s" % repr(e)[:80]


print("before:", vis(), flush=True)

try:
    api.update_repo_settings(repo_id=R, repo_type="dataset", private=False)
    print("update_repo_settings: OK", flush=True)
except Exception as e:
    print("update_repo_settings FAIL:", repr(e)[:300], flush=True)

print("after1:", vis(), flush=True)

if vis() is not False:
    r = requests.patch("https://huggingface.co/api/datasets/%s/settings" % R, headers=h,
                       json={"private": False}, timeout=60)
    print("PATCH /settings:", r.status_code, r.text[:300], flush=True)
    print("after2:", vis(), flush=True)

if vis() is not False:
    r = requests.post("https://huggingface.co/api/datasets/%s/settings" % R, headers=h,
                      json={"private": False}, timeout=60)
    print("POST /settings:", r.status_code, r.text[:300], flush=True)
    print("after3:", vis(), flush=True)

if vis() is not False:
    try:
        api.create_repo(repo_id="coderdecoder01/retirement-invite-mamta-public", repo_type="dataset",
                        private=False, exist_ok=True)
        print("new repo private:", vis("coderdecoder01/retirement-invite-mamta-public"), flush=True)
    except Exception as e:
        print("create public repo FAIL:", repr(e)[:300], flush=True)