|
|
|
|
|
from huggingface_hub import login, get_token, whoami |
|
|
import os |
|
|
import sys |
|
|
|
|
|
|
|
|
oname = os.name |
|
|
if oname == 'nt': |
|
|
osclear = 'cls' |
|
|
elif oname == 'posix': |
|
|
osclear = 'clear' |
|
|
else: |
|
|
osclear = '' |
|
|
def clear_screen(): |
|
|
os.system(osclear) |
|
|
|
|
|
|
|
|
if get_token() is not None: |
|
|
|
|
|
login(get_token()) |
|
|
tfound = 'true' |
|
|
else: |
|
|
|
|
|
login(input("API token not detected. Enter your HuggingFace (WRITE) token: ")) |
|
|
tfound = 'false' |
|
|
|
|
|
|
|
|
while True: |
|
|
if whoami().get('auth', {}).get('accessToken', {}).get('role', None) != 'write': |
|
|
clear_screen() |
|
|
if os.environ.get('HF_TOKEN', None) is not None: |
|
|
print(f''' |
|
|
You have the environment variable HF_TOKEN set. |
|
|
You cannot log in. |
|
|
Either set the environment variable to a (WRITE) token or remove it. |
|
|
''') |
|
|
input("Press enter to continue.") |
|
|
sys.exit("Exiting...") |
|
|
print("You do not have write access to this repository. Please use a valid token with (WRITE) access.") |
|
|
login(input("Enter your HuggingFace (WRITE) token: ")) |
|
|
continue |
|
|
break |
|
|
|
|
|
|
|
|
if tfound == 'false': |
|
|
print(f''' |
|
|
You are now logged in as {whoami().get('fullname', None)}. |
|
|
|
|
|
To logout, use the hf command line interface 'huggingface-cli logout' |
|
|
To view your active account, use 'huggingface-cli whoami' |
|
|
''') |
|
|
|