add login token detection and helpful notes
Browse files- create new branch.py +10 -1
create new branch.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import huggingface_hub
|
| 3 |
from huggingface_hub import create_branch
|
|
@@ -7,8 +8,16 @@ repo = input("Repository name: ")
|
|
| 7 |
r_type = input("Repo type (model) (dataset) (space): ")
|
| 8 |
branch = input("New branch name: ")
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
#login
|
| 11 |
-
huggingface_hub.login(
|
| 12 |
|
| 13 |
#create the branch
|
| 14 |
create_branch(repo, repo_type=r_type, branch=branch)
|
|
|
|
| 1 |
+
#import required modules
|
| 2 |
import os
|
| 3 |
import huggingface_hub
|
| 4 |
from huggingface_hub import create_branch
|
|
|
|
| 8 |
r_type = input("Repo type (model) (dataset) (space): ")
|
| 9 |
branch = input("New branch name: ")
|
| 10 |
|
| 11 |
+
#get token
|
| 12 |
+
if 'HF_TOKEN' in os.environ:
|
| 13 |
+
#if the variable is found then write it to hf_token:
|
| 14 |
+
hf_token = os.environ['HF_TOKEN']
|
| 15 |
+
else:
|
| 16 |
+
#if the variable is not found then prompt user to provide it:
|
| 17 |
+
hf_token = input("HF_TOKEN Variable not detected. Enter your HuggingFace token: ")
|
| 18 |
+
|
| 19 |
#login
|
| 20 |
+
huggingface_hub.login(hf_token)
|
| 21 |
|
| 22 |
#create the branch
|
| 23 |
create_branch(repo, repo_type=r_type, branch=branch)
|