Skip to content

Commit

Permalink
add progress bar to http_get
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel King <[email protected]>
  • Loading branch information
WeixiongLin and dakinggg committed Oct 19, 2023
1 parent 7da5117 commit 6ab3ba0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion scispacy/file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from hashlib import sha256

import requests
from tqdm import tqdm

CACHE_ROOT = Path(os.getenv("SCISPACY_CACHE", str(Path.home() / ".scispacy")))
DATASET_CACHE = str(CACHE_ROOT / "datasets")
Expand Down Expand Up @@ -96,9 +97,13 @@ def filename_to_url(filename: str, cache_dir: Optional[str] = None) -> Tuple[str

def http_get(url: str, temp_file: IO) -> None:
req = requests.get(url, stream=True)
total = int(req.headers.get("content-length", 0))
pbar = tqdm(total=total, unit="iB", unit_scale=True, unit_divisor=1024)
for chunk in req.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
temp_file.write(chunk)
size = temp_file.write(chunk)
pbar.update(size)
pbar.close()


def get_from_cache(url: str, cache_dir: Optional[str] = None) -> str:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
setup(
name="scispacy",
version=VERSION["VERSION"],
url="https://allenai.github.io/SciSpaCy/",
url="https://allenai.github.io/scispacy/",
author="Allen Institute for Artificial Intelligence",
author_email="[email protected]",
description="A full SpaCy pipeline and models for scientific/biomedical documents.",
Expand Down

0 comments on commit 6ab3ba0

Please sign in to comment.