MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / download_url_with_progress

Function download_url_with_progress

docling/utils/utils.py:47–65  ·  view source on GitHub ↗
(url: str, progress: bool = False)

Source from the content-addressed store, hash-verified

45
46
47def download_url_with_progress(url: str, progress: bool = False) -> BytesIO:
48 buf = BytesIO()
49 with requests.get(url, stream=True, allow_redirects=True) as response:
50 total_size = int(response.headers.get("content-length", 0))
51 progress_bar = tqdm(
52 total=total_size,
53 unit="B",
54 unit_scale=True,
55 unit_divisor=1024,
56 disable=(not progress),
57 )
58
59 for chunk in response.iter_content(10 * 1024):
60 buf.write(chunk)
61 progress_bar.update(len(chunk))
62 progress_bar.close()
63
64 buf.seek(0)
65 return buf

Callers 1

download_modelsMethod · 0.90

Calls 1

closeMethod · 0.45

Tested by

no test coverage detected