Commit
·
a2e360c
1
Parent(s):
2545811
Add civitai-to-hf-uploader
Browse files
app.py
CHANGED
@@ -23,14 +23,16 @@ def download_file(url, file_path, folder, api_key=None):
|
|
23 |
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
24 |
|
25 |
curl_cmd = ['curl', '--fail', '-L', '-o', full_path, url]
|
26 |
-
|
|
|
|
|
27 |
try:
|
28 |
result = subprocess.run(curl_cmd, check=True, capture_output=True, text=True)
|
29 |
except subprocess.CalledProcessError as e:
|
30 |
-
if '401' in e.stderr or '403' in e.stderr:
|
31 |
# Try again with authorization
|
32 |
-
|
33 |
-
curl_cmd.extend(['-H', f'Authorization: Bearer {
|
34 |
try:
|
35 |
result = subprocess.run(curl_cmd, check=True, capture_output=True, text=True)
|
36 |
except subprocess.CalledProcessError as e:
|
|
|
23 |
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
24 |
|
25 |
curl_cmd = ['curl', '--fail', '-L', '-o', full_path, url]
|
26 |
+
# Always use API key if provided
|
27 |
+
if api_key:
|
28 |
+
curl_cmd.extend(['-H', f'Authorization: Bearer {api_key}'])
|
29 |
try:
|
30 |
result = subprocess.run(curl_cmd, check=True, capture_output=True, text=True)
|
31 |
except subprocess.CalledProcessError as e:
|
32 |
+
if ('401' in e.stderr or '403' in e.stderr) and not api_key:
|
33 |
# Try again with authorization
|
34 |
+
api_key = os.environ.get("CIVITAI_API_KEY")
|
35 |
+
curl_cmd.extend(['-H', f'Authorization: Bearer {api_key}'])
|
36 |
try:
|
37 |
result = subprocess.run(curl_cmd, check=True, capture_output=True, text=True)
|
38 |
except subprocess.CalledProcessError as e:
|