added useful notes
Browse files- create new branch.py +28 -2
create new branch.py
CHANGED
|
@@ -6,18 +6,44 @@ from huggingface_hub import create_branch
|
|
| 6 |
#get user variables
|
| 7 |
repo = input("Repository name: ")
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
#get user variables
|
| 7 |
repo = input("Repository name: ")
|
| 8 |
r_type = input("Repo type (model) (dataset) (space): ")
|
| 9 |
+
branch = input("New branch name (No spaces): ")
|
| 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 |
+
tfound = "where are my doritos?"
|
| 16 |
else:
|
| 17 |
#if the variable is not found then prompt user to provide it:
|
| 18 |
+
hf_token = input("HF_TOKEN Variable not detected. Enter your HuggingFace (WRITE) token: ")
|
| 19 |
+
tfound = "false"
|
| 20 |
|
| 21 |
#login
|
| 22 |
huggingface_hub.login(hf_token)
|
| 23 |
|
| 24 |
#create the branch
|
| 25 |
create_branch(repo, repo_type=r_type, branch=branch)
|
| 26 |
+
|
| 27 |
+
#extra information
|
| 28 |
+
|
| 29 |
+
#Won't work if special characters are used
|
| 30 |
+
if r_type == model:
|
| 31 |
+
print(f"Branch created at https://huggingface/{repo}/tree/{branch}")
|
| 32 |
+
elif r_type == dataset:
|
| 33 |
+
print(f"Branch created at https://huggingface/datasets/{repo}/tree/{branch}")
|
| 34 |
+
elif r_type == space:
|
| 35 |
+
print(f"Branch created at https://huggingface/spaces/{repo}/tree/{branch}")
|
| 36 |
+
|
| 37 |
+
if tfound == 'false':
|
| 38 |
+
print('''
|
| 39 |
+
Set HF_TOKEN to a token with WRITE permissions to skip inputting token on each run.
|
| 40 |
+
|
| 41 |
+
On Unix systems, edit the file ~/.bashrc with an editor of your choise.
|
| 42 |
+
On a new line add: export HF_TOKEN=Your-HuggingFace-token-here
|
| 43 |
+
(Terminal Refresh Required)
|
| 44 |
+
To temporarily set a token to the active terminal use 'export HF_TOKEN=Your-HuggingFace-token-here'
|
| 45 |
+
|
| 46 |
+
On Windows use 'setx HF_TOKEN Your-HuggingFace-token-here'
|
| 47 |
+
(System Restart Required)
|
| 48 |
+
To temporarily set a token to the active terminal use 'set HF_TOKEN=Your-HuggingFace-token-here'
|
| 49 |
+
''')
|