Spaces:
Running
on
Zero
Running
on
Zero
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) | |