Skip to content

Commit d1969c5

Browse files
committed
chore: update tqdm declarative
1 parent 5ba5d16 commit d1969c5

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

fastembed/embedding.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -242,27 +242,14 @@ def download_file_from_gcs(cls, url: str, output_path: str, show_progress: bool
242242
if total_size_in_bytes == 0:
243243
print(f"Warning: Content-length header is missing or zero in the response from {url}.")
244244

245-
# Initialize the progress bar
246-
progress_bar = (
247-
tqdm(total=total_size_in_bytes, unit="iB", unit_scale=True)
248-
if total_size_in_bytes and show_progress
249-
else None
250-
)
245+
show_progress = total_size_in_bytes and show_progress
251246

252-
# Attempt to download the file
253-
try:
247+
with tqdm(total=total_size_in_bytes, unit="iB", unit_scale=True, disable=not show_progress) as progress_bar:
254248
with open(output_path, "wb") as file:
255-
for chunk in response.iter_content(chunk_size=1024): # Adjust chunk size to your preference
249+
for chunk in response.iter_content(chunk_size=1024):
256250
if chunk: # Filter out keep-alive new chunks
257-
if progress_bar is not None:
258-
progress_bar.update(len(chunk))
251+
progress_bar.update(len(chunk))
259252
file.write(chunk)
260-
except Exception as e:
261-
print(f"An error occurred while trying to download the file: {str(e)}")
262-
return
263-
finally:
264-
if progress_bar is not None:
265-
progress_bar.close()
266253
return output_path
267254

268255
@classmethod

0 commit comments

Comments
 (0)