Spaces:
Running
on
Zero
Running
on
Zero
File size: 875 Bytes
ef63ede 5e8e534 ef63ede 5e8e534 ef63ede 5e8e534 ef63ede 5e8e534 ef63ede 5e8e534 ef63ede 5e8e534 1bd0d83 5e8e534 ef63ede |
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 |
import time
import requests
from omegaconf import OmegaConf
def gh_download(repo, path, token):
paths = [path] if isinstance(path, str) else path
result = None
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github.raw+json",
}
for path in paths:
url = f"https://api.github.com/repos/{repo}/contents/{path}"
response = requests.get(url, headers=headers)
if response.status_code != 200:
raise Exception(f"Failed to download {path} from {repo}")
if result is None:
result = response.json()
elif isinstance(result, list):
result.extend(response.json())
elif isinstance(result, dict):
result.update(response.json())
time.sleep(0.1)
return result
OmegaConf.register_new_resolver("gh_download", gh_download)
|