@@ -127,22 +127,26 @@ def fetch_models_task(nc: NextcloudApp, models: dict[str, dict], progress_init_s
127
127
percent_for_each = min (int ((100 - progress_init_start_value ) / len (models )), 99 )
128
128
for model in models :
129
129
if model .startswith (("http://" , "https://" )):
130
- __fetch_model_as_file (current_progress , percent_for_each , nc , model , models [model ])
130
+ models [model ]["path" ] = __fetch_model_as_file (
131
+ current_progress , percent_for_each , nc , model , models [model ]
132
+ )
131
133
else :
132
- __fetch_model_as_snapshot (current_progress , percent_for_each , nc , model , models [model ])
134
+ models [model ]["path" ] = __fetch_model_as_snapshot (
135
+ current_progress , percent_for_each , nc , model , models [model ]
136
+ )
133
137
current_progress += percent_for_each
134
138
nc .set_init_status (100 )
135
139
136
140
137
141
def __fetch_model_as_file (
138
142
current_progress : int , progress_for_task : int , nc : NextcloudApp , model_path : str , download_options : dict
139
- ) -> None :
143
+ ) -> str | None :
140
144
result_path = download_options .pop ("save_path" , urlparse (model_path ).path .split ("/" )[- 1 ])
141
145
try :
142
146
with httpx .stream ("GET" , model_path , follow_redirects = True ) as response :
143
147
if not response .is_success :
144
148
nc .log (LogLvl .ERROR , f"Downloading of '{ model_path } ' returned { response .status_code } status." )
145
- return
149
+ return None
146
150
downloaded_size = 0
147
151
linked_etag = ""
148
152
for each_history in response .history :
@@ -163,7 +167,7 @@ def __fetch_model_as_file(
163
167
sha256_hash .update (byte_block )
164
168
if f'"{ sha256_hash .hexdigest ()} "' == linked_etag :
165
169
nc .set_init_status (min (current_progress + progress_for_task , 99 ))
166
- return
170
+ return None
167
171
168
172
with builtins .open (result_path , "wb" ) as file :
169
173
last_progress = current_progress
@@ -174,13 +178,17 @@ def __fetch_model_as_file(
174
178
if new_progress != last_progress :
175
179
nc .set_init_status (new_progress )
176
180
last_progress = new_progress
181
+
182
+ return result_path
177
183
except Exception as e : # noqa pylint: disable=broad-exception-caught
178
184
nc .log (LogLvl .ERROR , f"Downloading of '{ model_path } ' raised an exception: { e } " )
179
185
186
+ return None
187
+
180
188
181
189
def __fetch_model_as_snapshot (
182
190
current_progress : int , progress_for_task , nc : NextcloudApp , mode_name : str , download_options : dict
183
- ) -> None :
191
+ ) -> str :
184
192
from huggingface_hub import snapshot_download # noqa isort:skip pylint: disable=C0415 disable=E0401
185
193
from tqdm import tqdm # noqa isort:skip pylint: disable=C0415 disable=E0401
186
194
@@ -191,7 +199,9 @@ def display(self, msg=None, pos=None):
191
199
192
200
workers = download_options .pop ("max_workers" , 2 )
193
201
cache = download_options .pop ("cache_dir" , persistent_storage ())
194
- snapshot_download (mode_name , tqdm_class = TqdmProgress , ** download_options , max_workers = workers , cache_dir = cache )
202
+ return snapshot_download (
203
+ mode_name , tqdm_class = TqdmProgress , ** download_options , max_workers = workers , cache_dir = cache
204
+ )
195
205
196
206
197
207
def __nc_app (request : HTTPConnection ) -> dict :
0 commit comments