Anthonyg5005 commited on
Commit
a8d61ee
·
verified ·
1 Parent(s): a4ebec9

ensure user chose valid option

Browse files
Files changed (1) hide show
  1. create new branch.py +12 -5
create new branch.py CHANGED
@@ -5,14 +5,21 @@ from huggingface_hub import create_branch
5
 
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: ")
@@ -25,15 +32,14 @@ huggingface_hub.login(hf_token)
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.
@@ -47,3 +53,4 @@ if tfound == 'false':
47
  (System Restart Required)
48
  To temporarily set a token to the active terminal use 'set HF_TOKEN=Your-HuggingFace-token-here'
49
  ''')
 
 
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: ")
 
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/{repo}/tree/{branch}")
38
  elif r_type == dataset:
39
  print(f"Branch created at https://huggingface/datasets/{repo}/tree/{branch}")
40
  elif r_type == space:
41
  print(f"Branch created at https://huggingface/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.
 
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.")