|
|
|
import os |
|
import huggingface_hub |
|
from huggingface_hub import create_branch, delete_branch |
|
|
|
|
|
def clear_screen(): |
|
os.system('cls' if os.name == 'nt' else 'clear') |
|
|
|
|
|
clear_screen() |
|
|
|
|
|
while True: |
|
cord = input("What would you like to do? (create) (delete): ").lower() |
|
|
|
if cord not in ['create', 'delete']: |
|
clear_screen() |
|
print("Please choose one of the two options.") |
|
continue |
|
|
|
break |
|
clear_screen() |
|
repo = input("Repository name (User/Repo): ") |
|
clear_screen() |
|
while True: |
|
r_type = input("Repo type (model) (dataset) (space): ").lower() |
|
|
|
if r_type not in ['model', 'dataset', 'space']: |
|
clear_screen() |
|
print("Please choose one of the three options.") |
|
continue |
|
|
|
break |
|
clear_screen() |
|
branch = input("Branch name (No spaces): ") |
|
clear_screen() |
|
|
|
|
|
if 'HF_TOKEN' in os.environ: |
|
|
|
hf_token = os.environ['HF_TOKEN'] |
|
tfound = "Where are my doritos?" |
|
else: |
|
|
|
hf_token = input("HF_TOKEN Variable not detected. Enter your HuggingFace (WRITE) token: ") |
|
tfound = "false" |
|
|
|
|
|
huggingface_hub.login(hf_token) |
|
|
|
|
|
if cord == 'create': |
|
create_branch(repo, repo_type=r_type, branch=branch) |
|
else: |
|
delete_branch(repo, repo_type=r_type, branch=branch) |
|
|
|
|
|
clear_screen() |
|
|
|
if cord == 'create': |
|
if r_type == 'model': |
|
print(f"Branch created at https://huggingface.co/{repo}/tree/{branch}") |
|
elif r_type == 'dataset': |
|
print(f"Branch created at https://huggingface.co/datasets/{repo}/tree/{branch}") |
|
elif r_type == 'space': |
|
print(f"Branch created at https://huggingface.co/spaces/{repo}/tree/{branch}") |
|
else: |
|
if r_type == 'model': |
|
print(f"Branch deleted on {r_type} https://huggingface.co/{repo}") |
|
elif r_type == 'dataset': |
|
print(f"Branch deleted on {r_type} https://huggingface.co/datasets/{repo}") |
|
elif r_type == 'space': |
|
print(f"Branch deleted on {r_type} https://huggingface.co/spaces/{repo}") |
|
|
|
if tfound == 'false': |
|
print(''' |
|
Set HF_TOKEN to a token with WRITE permissions to skip inputting token on each run. |
|
|
|
On Unix systems, edit the file ~/.bashrc with an editor of your choise. |
|
On a new line add: export HF_TOKEN=Your-HuggingFace-token-here |
|
(Terminal Refresh Required) |
|
To temporarily set a token to the active terminal use 'export HF_TOKEN=Your-HuggingFace-token-here' |
|
|
|
On Windows use 'setx HF_TOKEN Your-HuggingFace-token-here' |
|
(System Restart Required) |
|
To temporarily set a token to the active terminal use 'set HF_TOKEN=Your-HuggingFace-token-here' |
|
''') |
|
input("Press enter to continue.") |
|
|