Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Downloading Functionality #6

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pranaam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tarfile
import requests
from .logging import get_logger
from tqdm.auto import tqdm

logger = get_logger()

Expand All @@ -16,8 +17,12 @@ def download_file(url, target, file_name):
try:
print("Download models from dataverse...")
# download the file
r = requests.get(url, allow_redirects=True)
open(file_path, "wb").write(r.content)
with requests.Session() as s:
r = s.get(REPO_BASE_URL, stream=True, allow_redirects=True)
with tqdm(total=int(r.headers['Content-Length']), unit='iB', unit_scale=True, desc=file_name, initial=0, miniters=1, ascii=True, colour='cyan', leave=True) as pbar:
with open(file_path, 'wb') as fd:
for chunk in r.iter_content(chunk_size=1024**2):
pbar.update(fd.write(chunk))
# untar
with tarfile.open(file_path, "r:gz") as tar_ref:
def is_within_directory(directory, target):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pandas
numpy
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
wheel>=0.38.0 # not directly required, pinned by Snyk to avoid a vulnerability
tqdm