John6666 commited on
Commit
e9925f7
·
verified ·
1 Parent(s): 23f79a8

Upload utils.py

Browse files
Files changed (1) hide show
  1. utils.py +7 -8
utils.py CHANGED
@@ -130,22 +130,21 @@ def download_thing(directory, url, civitai_api_key="", progress=gr.Progress(trac
130
  if "drive.google.com" in url:
131
  original_dir = os.getcwd()
132
  os.chdir(directory)
133
- os.system(f"gdown --fuzzy {url}")
134
  os.chdir(original_dir)
135
  elif "huggingface.co" in url:
136
  url = url.replace("?download=true", "")
137
  if "/blob/" in url: url = url.replace("/blob/", "/resolve/")
138
  download_hf_file(directory, url)
139
  elif "civitai.com" in url:
140
- if "?" in url:
141
- url = url.split("?")[0]
142
  if civitai_api_key:
143
- url = url + f"?token={civitai_api_key}"
144
- os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
 
145
  else:
146
  print("You need an API key to download Civitai models.")
147
  else:
148
- os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
149
  except Exception as e:
150
  print(f"Failed to download: {e}")
151
 
@@ -181,8 +180,8 @@ def get_download_file(temp_dir, url, civitai_key, progress=gr.Progress(track_tqd
181
  return ""
182
  print(f"Download completed: {url}")
183
  return new_file
184
- except Exception:
185
- print(f"Download failed: {url}")
186
  return ""
187
 
188
 
 
130
  if "drive.google.com" in url:
131
  original_dir = os.getcwd()
132
  os.chdir(directory)
133
+ subprocess.run(f"gdown --fuzzy '{url}'", shell=True)
134
  os.chdir(original_dir)
135
  elif "huggingface.co" in url:
136
  url = url.replace("?download=true", "")
137
  if "/blob/" in url: url = url.replace("/blob/", "/resolve/")
138
  download_hf_file(directory, url)
139
  elif "civitai.com" in url:
 
 
140
  if civitai_api_key:
141
+ url = url + f"&token={civitai_api_key}" if "?" in url else url + f"?token={civitai_api_key}"
142
+ print(f"Downloading {url}")
143
+ subprocess.run(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} '{url}'", shell=True)
144
  else:
145
  print("You need an API key to download Civitai models.")
146
  else:
147
+ os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} '{url}'")
148
  except Exception as e:
149
  print(f"Failed to download: {e}")
150
 
 
180
  return ""
181
  print(f"Download completed: {url}")
182
  return new_file
183
+ except Exception as e:
184
+ print(f"Download failed: {url} {e}")
185
  return ""
186
 
187