Spaces:
Running
Running
Upload 2 files
Browse files
utils.py
CHANGED
@@ -149,9 +149,10 @@ def download_thing(directory, url, civitai_api_key="", progress=gr.Progress(trac
|
|
149 |
print(f"Failed to download: {e}")
|
150 |
|
151 |
|
152 |
-
def get_local_file_list(dir_path):
|
153 |
file_list = []
|
154 |
-
|
|
|
155 |
if file.is_file():
|
156 |
file_path = str(file)
|
157 |
file_list.append(file_path)
|
@@ -171,9 +172,10 @@ def get_download_file(temp_dir, url, civitai_key, progress=gr.Progress(track_tqd
|
|
171 |
new_file = f"{temp_dir}/{url.split('/')[-1]}"
|
172 |
else:
|
173 |
print(f"Start downloading: {url}")
|
174 |
-
|
|
|
175 |
download_thing(temp_dir, url.strip(), civitai_key)
|
176 |
-
after = get_local_file_list(temp_dir)
|
177 |
new_file = list_sub(after, before)[0] if list_sub(after, before) else ""
|
178 |
if not new_file:
|
179 |
print(f"Download failed: {url}")
|
|
|
149 |
print(f"Failed to download: {e}")
|
150 |
|
151 |
|
152 |
+
def get_local_file_list(dir_path, recursive=False):
|
153 |
file_list = []
|
154 |
+
pattern = "**/*.*" if recursive else "*/*.*"
|
155 |
+
for file in Path(dir_path).glob(pattern):
|
156 |
if file.is_file():
|
157 |
file_path = str(file)
|
158 |
file_list.append(file_path)
|
|
|
172 |
new_file = f"{temp_dir}/{url.split('/')[-1]}"
|
173 |
else:
|
174 |
print(f"Start downloading: {url}")
|
175 |
+
recursive = False if "huggingface.co" in url else True
|
176 |
+
before = get_local_file_list(temp_dir, recursive)
|
177 |
download_thing(temp_dir, url.strip(), civitai_key)
|
178 |
+
after = get_local_file_list(temp_dir, recursive)
|
179 |
new_file = list_sub(after, before)[0] if list_sub(after, before) else ""
|
180 |
if not new_file:
|
181 |
print(f"Download failed: {url}")
|