update civit downloader

This commit is contained in:
Vladimir Mandic
2024-03-16 12:42:33 -04:00
parent b0cb57ee23
commit 8c53dfdcd0
3 changed files with 17 additions and 4 deletions
+9 -1
View File
@@ -1,5 +1,6 @@
import os
import time
import json
import shutil
import importlib
from typing import Dict
@@ -117,6 +118,12 @@ def download_civit_model_thread(model_name, model_url, model_path, model_type, t
try:
with open(temp_file, 'ab') as f:
for data in r.iter_content(block_size):
if written == 0:
try: # check if response is JSON message instead of bytes
shared.log.error(f'Model download: response={json.loads(data.decode("utf-8"))}')
raise ValueError('response: type=json expected=bytes')
except Exception: # this is good
pass
written = written + len(data)
f.write(data)
download_pbar.update(task, description="Download", completed=written)
@@ -136,7 +143,8 @@ def download_civit_model_thread(model_name, model_url, model_path, model_type, t
download_pbar.remove_task(task)
if starting_pos+total_size != written:
shared.log.warning(f'{res} written={round(written/1024/1024)}Mb incomplete download')
else:
elif os.path.exists(temp_file):
shared.log.debug(f'Model download complete: temp="{temp_file}" path="{model_file}"')
os.rename(temp_file, model_file)
shared.state.end()
return res