Replaced by Manage Branch.py
Browse files- create new branch.py +0 -56
create new branch.py
DELETED
|
@@ -1,56 +0,0 @@
|
|
| 1 |
-
#import required modules
|
| 2 |
-
import os
|
| 3 |
-
import huggingface_hub
|
| 4 |
-
from huggingface_hub import create_branch
|
| 5 |
-
|
| 6 |
-
#get user variables
|
| 7 |
-
repo = input("Repository name: ")
|
| 8 |
-
while True:
|
| 9 |
-
r_type = input("Repo type (model) (dataset) (space): ").lower()
|
| 10 |
-
|
| 11 |
-
if r_type not in ['model', 'dataset', 'space']:
|
| 12 |
-
print("Please choose one of the three options.")
|
| 13 |
-
continue
|
| 14 |
-
|
| 15 |
-
break
|
| 16 |
-
branch = input("New branch name (No spaces): ")
|
| 17 |
-
|
| 18 |
-
#get token
|
| 19 |
-
if 'HF_TOKEN' in os.environ:
|
| 20 |
-
#if the variable is found then write it to hf_token:
|
| 21 |
-
hf_token = os.environ['HF_TOKEN']
|
| 22 |
-
tfound = "true"
|
| 23 |
-
else:
|
| 24 |
-
#if the variable is not found then prompt user to provide it:
|
| 25 |
-
hf_token = input("HF_TOKEN Variable not detected. Enter your HuggingFace (WRITE) token: ")
|
| 26 |
-
tfound = "false"
|
| 27 |
-
|
| 28 |
-
#login
|
| 29 |
-
huggingface_hub.login(hf_token)
|
| 30 |
-
|
| 31 |
-
#create the branch
|
| 32 |
-
create_branch(repo, repo_type=r_type, branch=branch)
|
| 33 |
-
|
| 34 |
-
#extra information
|
| 35 |
-
#won't work if special characters are used
|
| 36 |
-
if r_type == 'model':
|
| 37 |
-
print(f"Branch created at https://huggingface.co/{repo}/tree/{branch}")
|
| 38 |
-
elif r_type == 'dataset':
|
| 39 |
-
print(f"Branch created at https://huggingface.co/datasets/{repo}/tree/{branch}")
|
| 40 |
-
elif r_type == 'space':
|
| 41 |
-
print(f"Branch created at https://huggingface.co/spaces/{repo}/tree/{branch}")
|
| 42 |
-
#if token wasn't found then display following text:
|
| 43 |
-
if tfound == 'false':
|
| 44 |
-
print('''
|
| 45 |
-
Set HF_TOKEN to a token with WRITE permissions to skip inputting token on each run.
|
| 46 |
-
|
| 47 |
-
On Unix systems, edit the file ~/.bashrc with an editor of your choise.
|
| 48 |
-
On a new line add: export HF_TOKEN=Your-HuggingFace-token-here
|
| 49 |
-
(Terminal Refresh Required)
|
| 50 |
-
To temporarily set a token to the active terminal use 'export HF_TOKEN=Your-HuggingFace-token-here'
|
| 51 |
-
|
| 52 |
-
On Windows use 'setx HF_TOKEN Your-HuggingFace-token-here'
|
| 53 |
-
(System Restart Required)
|
| 54 |
-
To temporarily set a token to the active terminal use 'set HF_TOKEN=Your-HuggingFace-token-here'
|
| 55 |
-
''')
|
| 56 |
-
input("Press enter to continue.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|