Skip to content

Commit 7a16699

Browse files
committed
Fix download issue
1 parent a0369b4 commit 7a16699

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

gimpopenvino/plugins/openvino_utils/tools/model_manager.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,20 @@ def compile_and_export_model(core, model_path, output_path, device='NPU', config
345345
tb_str = traceback.format_exc()
346346
raise RuntimeError(f"Model compilation or export failed for {model_path} on device {device}.\nDetails: {tb_str}")
347347

348-
def download_file_with_progress(url, local_filename, callback, total_bytes_downloaded, total_file_list_size):
348+
def download_file_with_progress(url, local_filename, callback, total_bytes_downloaded, total_file_list_size,total_file_size):
349349
response = requests.get(url, stream=True)
350-
total_size = int(response.headers.get('content-length', 0))
350+
total_size = int(total_file_size)
351351
downloaded_size = 0
352352

353+
percent_complete = 0
353354
percent_complete_last = -1.0;
354355
with open(local_filename, 'wb') as file:
355356
for data in response.iter_content(chunk_size=4096):
356357
file.write(data)
357358
downloaded_size += len(data)
358359
total_bytes_downloaded += len(data)
359-
percent_complete = (downloaded_size / total_size) * 100
360+
if total_size != 0:
361+
percent_complete = (downloaded_size / total_size) * 100
360362

361363
if percent_complete - percent_complete_last > 1:
362364
percent_complete_last = percent_complete
@@ -764,7 +766,7 @@ def bytes_downloaded_callback(total_bytes_downloaded, total_bytes_to_download):
764766
os.makedirs(subfolder, exist_ok=True)
765767

766768
#print("Downloading", download_list_item["url"], " to ", local_filename)
767-
downloaded_size = download_file_with_progress(download_list_item["url"], local_filename, bytes_downloaded_callback, total_bytes_downloaded, total_file_list_size)
769+
downloaded_size = download_file_with_progress(download_list_item["url"], local_filename, bytes_downloaded_callback, total_bytes_downloaded, total_file_list_size, download_list_item["size"])
768770

769771
if "cancelled" in self.model_install_status[model_id]:
770772
return True

0 commit comments

Comments
 (0)