Download scripts/hf_identity.py from StarAtNyte1/beam-boot: direct link, hf CLI and curl.
- Browser
- Download file 896 Bytes
-
https://huggingface.co/StarAtNyte1/beam-boot/resolve/main/scripts/hf_identity.py
- Command line
-
hf download hf://StarAtNyte1/beam-boot/scripts/hf_identity.py
-
curl -L -o hf_identity.py https://huggingface.co/StarAtNyte1/beam-boot/resolve/main/scripts/hf_identity.py
896 Bytes
| import json | |
| import os | |
| import urllib.request | |
| import modal | |
| app = modal.App('beamboot-hf-identity') | |
| def identity(): | |
| token = (os.environ.get('HF_TOKEN') or os.environ.get('HUGGING_FACE_HUB_TOKEN') or os.environ.get('HUGGINGFACE_TOKEN') or os.environ.get('HUGGINGFACEHUB_API_TOKEN')) | |
| if not token: raise RuntimeError('No recognized HF token variable') | |
| request = urllib.request.Request('https://huggingface.co/api/whoami-v2', headers={'Authorization': 'Bearer ' + token}) | |
| with urllib.request.urlopen(request, timeout=20) as response: | |
| data = json.load(response) | |
| return {'name': data.get('name'), 'type': data.get('type'), 'role': data.get('auth', {}).get('accessToken', {}).get('role')} | |
| def main(): print(identity.remote()) | |