Kaggle support
Browse files+ Colab warnings
- manage branches.py +27 -17
manage branches.py
CHANGED
|
@@ -61,17 +61,22 @@ if cord == 'create':
|
|
| 61 |
clear_screen()
|
| 62 |
|
| 63 |
#get token
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
if get_token() is not None:
|
| 65 |
#if the token is found then log in:
|
| 66 |
login(get_token())
|
| 67 |
tfound = "Where are my doritos?"
|
| 68 |
else:
|
| 69 |
-
if os.environ.get('KAGGLE_KERNEL_RUN_TYPE', None) is not None: #check if user in kaggle
|
| 70 |
-
print('''
|
| 71 |
-
When using Kaggle, make sure to use the secret key HF_TOKEN with a 'WRITE' token.
|
| 72 |
-
This will prevent the need to login every time you run the script.
|
| 73 |
-
Set your secrets with the secrets add-on on the top of the screen.
|
| 74 |
-
''')
|
| 75 |
#if the token is not found then prompt user to provide it:
|
| 76 |
login(input("API token not detected. Enter your HuggingFace (WRITE) token: "))
|
| 77 |
tfound = "false"
|
|
@@ -80,21 +85,26 @@ else:
|
|
| 80 |
while True:
|
| 81 |
if whoami().get('auth', {}).get('accessToken', {}).get('role', None) != 'write':
|
| 82 |
clear_screen()
|
| 83 |
-
if os.environ.get('HF_TOKEN', None) is not None: #if environ finds HF_TOKEN as
|
| 84 |
-
print(
|
| 85 |
You have the environment variable HF_TOKEN set.
|
| 86 |
You cannot log in.
|
| 87 |
-
Either set the environment variable to a
|
| 88 |
-
|
| 89 |
input("Press enter to continue.")
|
| 90 |
exit()
|
| 91 |
-
|
| 92 |
-
if os.environ.get('KAGGLE_KERNEL_RUN_TYPE', None) is not None: #check if user in kaggle
|
| 93 |
print('''
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
''')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
print("You do not have write access to this repository. Please use a valid token with (WRITE) access.")
|
| 99 |
login(input("Enter your HuggingFace (WRITE) token: "))
|
| 100 |
continue
|
|
@@ -164,10 +174,10 @@ else:
|
|
| 164 |
#if token wasn't found from line 60 then display following text:
|
| 165 |
if tfound == 'false':
|
| 166 |
print(f'''
|
| 167 |
-
|
| 168 |
|
| 169 |
To logout, use the hf command line interface 'huggingface-cli logout'
|
| 170 |
-
|
| 171 |
''')
|
| 172 |
|
| 173 |
input("Press enter to continue.")
|
|
|
|
| 61 |
clear_screen()
|
| 62 |
|
| 63 |
#get token
|
| 64 |
+
if os.environ.get('KAGGLE_KERNEL_RUN_TYPE', None) is not None: #check if user in kaggle
|
| 65 |
+
from kaggle_secrets import UserSecretsClient
|
| 66 |
+
from kaggle_web_client import BackendError
|
| 67 |
+
try:
|
| 68 |
+
login(UserSecretsClient().get_secret("HF_TOKEN")) #login if token secret found
|
| 69 |
+
except BackendError:
|
| 70 |
+
print('''
|
| 71 |
+
When using Kaggle, make sure to use the secret key HF_TOKEN with a 'WRITE' token.
|
| 72 |
+
This will prevent the need to login every time you run the script.
|
| 73 |
+
Set your secrets with the secrets add-on on the top of the screen.
|
| 74 |
+
''')
|
| 75 |
if get_token() is not None:
|
| 76 |
#if the token is found then log in:
|
| 77 |
login(get_token())
|
| 78 |
tfound = "Where are my doritos?"
|
| 79 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
#if the token is not found then prompt user to provide it:
|
| 81 |
login(input("API token not detected. Enter your HuggingFace (WRITE) token: "))
|
| 82 |
tfound = "false"
|
|
|
|
| 85 |
while True:
|
| 86 |
if whoami().get('auth', {}).get('accessToken', {}).get('role', None) != 'write':
|
| 87 |
clear_screen()
|
| 88 |
+
if os.environ.get('HF_TOKEN', None) is not None: #if environ finds HF_TOKEN as read-only then display following text and exit:
|
| 89 |
+
print('''
|
| 90 |
You have the environment variable HF_TOKEN set.
|
| 91 |
You cannot log in.
|
| 92 |
+
Either set the environment variable to a 'WRITE' token or remove it.
|
| 93 |
+
''')
|
| 94 |
input("Press enter to continue.")
|
| 95 |
exit()
|
| 96 |
+
if os.environ.get('COLAB_BACKEND_VERSION', None) is not None:
|
|
|
|
| 97 |
print('''
|
| 98 |
+
Your Colab secret key is read-only
|
| 99 |
+
Please switch your key to 'write' or disable notebook access on the left.
|
| 100 |
+
For now, you are stuck in a loop
|
| 101 |
''')
|
| 102 |
+
elif os.environ.get('KAGGLE_KERNEL_RUN_TYPE', None) is not None:
|
| 103 |
+
print('''
|
| 104 |
+
Your Kaggle secret key is read-only
|
| 105 |
+
Please switch your key to 'write' or unattach from notebook in add-ons at the top.
|
| 106 |
+
Having a read-only key attched will require login every time.
|
| 107 |
+
''')
|
| 108 |
print("You do not have write access to this repository. Please use a valid token with (WRITE) access.")
|
| 109 |
login(input("Enter your HuggingFace (WRITE) token: "))
|
| 110 |
continue
|
|
|
|
| 174 |
#if token wasn't found from line 60 then display following text:
|
| 175 |
if tfound == 'false':
|
| 176 |
print(f'''
|
| 177 |
+
You are now logged in as {whoami().get('fullname', None)}.
|
| 178 |
|
| 179 |
To logout, use the hf command line interface 'huggingface-cli logout'
|
| 180 |
+
To view your active account, use 'huggingface-cli whoami'
|
| 181 |
''')
|
| 182 |
|
| 183 |
input("Press enter to continue.")
|