Skip to content
Snippets Groups Projects

Release 1.0.0b2.

Merged Mateusz Klimaszewski requested to merge config_package into develop
Viewing commit f3f0c4a8
Show latest version
1 file
+ 6
7
Compare changes
  • Side-by-side
  • Inline
+ 6
7
import errno
import errno
import logging
import logging
import math
import os
import os
import requests
import requests
@@ -23,18 +22,18 @@ def download_file(model_name, force=False):
@@ -23,18 +22,18 @@ def download_file(model_name, force=False):
if os.path.exists(location) and not force:
if os.path.exists(location) and not force:
logger.debug("Using cached model.")
logger.debug("Using cached model.")
return location
return location
chunk_size = 1024 * 10
chunk_size = 1024
logger.info(url)
logger.info(url)
try:
try:
with _requests_retry_session(retries=2).get(url, stream=True) as r:
with _requests_retry_session(retries=2).get(url, stream=True) as r:
total_length = math.ceil(int(r.headers.get("content-length")) / chunk_size)
pbar = tqdm.tqdm(unit="B", total=int(r.headers.get("content-length")),
 
unit_divisor=chunk_size, unit_scale=True)
with open(location, "wb") as f:
with open(location, "wb") as f:
with tqdm.tqdm(total=total_length) as pbar:
with pbar:
for chunk in r.raw.stream(chunk_size, decode_content=False):
for chunk in r.iter_content(chunk_size):
if chunk:
if chunk:
f.write(chunk)
f.write(chunk)
f.flush()
pbar.update(len(chunk))
pbar.update(1)
except exceptions.RetryError:
except exceptions.RetryError:
raise ConnectionError(f"Couldn't find or download model {model_name}.tar.gz. "
raise ConnectionError(f"Couldn't find or download model {model_name}.tar.gz. "
"Check if model name is correct or try again later!")
"Check if model name is correct or try again later!")