Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,8 @@ TRUSTED_UPLOADERS = ["KappaNeuro", "CiroN2022", "multimodalart", "Norod78", "joa
|
|
| 15 |
def get_json_data(url):
|
| 16 |
url_split = url.split('/')
|
| 17 |
print("url_split: ", url_split)
|
| 18 |
-
api_url = f"https://civitai.com/api/v1/models/{url_split[4]}?
|
|
|
|
| 19 |
try:
|
| 20 |
response = requests.get(api_url)
|
| 21 |
response.raise_for_status()
|
|
@@ -123,14 +124,26 @@ def download_files(info, folder="."):
|
|
| 123 |
return downloaded_files
|
| 124 |
|
| 125 |
def download_file(url, filename, folder="."):
|
|
|
|
| 126 |
try:
|
| 127 |
-
response = requests.get(url)
|
| 128 |
response.raise_for_status()
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
except requests.exceptions.RequestException as e:
|
| 132 |
raise gr.Error(f"Error downloading file: {e}")
|
| 133 |
|
|
|
|
|
|
|
|
|
|
| 134 |
def process_url(url, profile, do_download=True, folder="."):
|
| 135 |
json_data = get_json_data(url)
|
| 136 |
if json_data:
|
|
|
|
| 15 |
def get_json_data(url):
|
| 16 |
url_split = url.split('/')
|
| 17 |
print("url_split: ", url_split)
|
| 18 |
+
api_url = f"https://civitai.com/api/v1/models/{url_split[4]}?
|
| 19 |
+
token={os.environ['CIVITAI_API']}"
|
| 20 |
try:
|
| 21 |
response = requests.get(api_url)
|
| 22 |
response.raise_for_status()
|
|
|
|
| 124 |
return downloaded_files
|
| 125 |
|
| 126 |
def download_file(url, filename, folder="."):
|
| 127 |
+
headers = {}
|
| 128 |
try:
|
| 129 |
+
response = requests.get(url, headers=headers)
|
| 130 |
response.raise_for_status()
|
| 131 |
+
except requests.exceptions.HTTPError as e:
|
| 132 |
+
if api_key and response.status_code == 401:
|
| 133 |
+
headers['Authorization'] = f'Bearer {os.environ['CIVITAI_API']}'
|
| 134 |
+
try:
|
| 135 |
+
response = requests.get(url, headers=headers)
|
| 136 |
+
response.raise_for_status()
|
| 137 |
+
except requests.exceptions.RequestException as e:
|
| 138 |
+
raise gr.Error(f"Error downloading file: {e}")
|
| 139 |
+
else:
|
| 140 |
+
raise gr.Error(f"Error downloading file: {e}")
|
| 141 |
except requests.exceptions.RequestException as e:
|
| 142 |
raise gr.Error(f"Error downloading file: {e}")
|
| 143 |
|
| 144 |
+
with open(f"{folder}/{filename}", 'wb') as f:
|
| 145 |
+
f.write(response.content)
|
| 146 |
+
|
| 147 |
def process_url(url, profile, do_download=True, folder="."):
|
| 148 |
json_data = get_json_data(url)
|
| 149 |
if json_data:
|