idlebg commited on
Commit
f7566a0
1 Parent(s): 876d6e2

token: str added for private repos

Browse files

HTTP 401 Unauthorized Error FIX
401 Unauthorized Error during attempts to download models from private repositories on the Hugging Face model hub. The issue arose due to a missing token in the configuration required for accessing models from private repositories.

Modified convert_single to accept and pass the token to hf_hub_download
& convert to accept and pass the token to convert_single

Files changed (1) hide show
  1. convert.py +4 -4
convert.py CHANGED
@@ -19,10 +19,10 @@ from transformers import CONFIG_MAPPING
19
  COMMIT_MESSAGE = " This PR adds fp32 and fp16 weights in safetensors format to {}"
20
 
21
 
22
- def convert_single(model_id: str, filename: str, folder: str, progress: Any):
23
  progress(0, desc="Downloading model")
24
  local_file = os.path.join(model_id, filename)
25
- ckpt_file = local_file if os.path.isfile(local_file) else hf_hub_download(repo_id=model_id, filename=filename)
26
 
27
  pipeline = StableDiffusionXLPipeline.from_single_file(ckpt_file)
28
 
@@ -55,7 +55,7 @@ def convert(token: str, model_id: str, filename: str, progress=gr.Progress()):
55
  os.makedirs(folder)
56
  new_pr = None
57
  try:
58
- folder = convert_single(model_id, filename, folder, progress)
59
  progress(0.7, desc="Uploading to Hub")
60
  new_pr = api.upload_folder(folder_path=folder, path_in_repo="./", repo_id=model_id, repo_type="model", token=token, commit_message=pr_title, commit_description=COMMIT_MESSAGE.format(model_id), create_pr=True)
61
  pr_number = new_pr.split("%2F")[-1].split("/")[0]
@@ -66,4 +66,4 @@ def convert(token: str, model_id: str, filename: str, progress=gr.Progress()):
66
  finally:
67
  shutil.rmtree(folder)
68
 
69
- return link
 
19
  COMMIT_MESSAGE = " This PR adds fp32 and fp16 weights in safetensors format to {}"
20
 
21
 
22
+ def convert_single(model_id: str, filename: str, folder: str, progress: Any, token: str):
23
  progress(0, desc="Downloading model")
24
  local_file = os.path.join(model_id, filename)
25
+ ckpt_file = local_file if os.path.isfile(local_file) else hf_hub_download(repo_id=model_id, filename=filename, token=token)
26
 
27
  pipeline = StableDiffusionXLPipeline.from_single_file(ckpt_file)
28
 
 
55
  os.makedirs(folder)
56
  new_pr = None
57
  try:
58
+ folder = convert_single(model_id, filename, folder, progress, token)
59
  progress(0.7, desc="Uploading to Hub")
60
  new_pr = api.upload_folder(folder_path=folder, path_in_repo="./", repo_id=model_id, repo_type="model", token=token, commit_message=pr_title, commit_description=COMMIT_MESSAGE.format(model_id), create_pr=True)
61
  pr_number = new_pr.split("%2F")[-1].split("/")[0]
 
66
  finally:
67
  shutil.rmtree(folder)
68
 
69
+ return link