Datasets:

Modalities:
Image
Languages:
English
ArXiv:
Tags:
code
License:
yueyin27 commited on
Commit
14ba72f
·
verified ·
1 Parent(s): c76a6a7

Upload file

Browse files
Files changed (1) hide show
  1. upload_to_hf.py +13 -3
upload_to_hf.py CHANGED
@@ -30,6 +30,16 @@ except Exception: # pragma: no cover
30
  from huggingface_hub import HfHubError as HfHubHTTPError # type: ignore[assignment]
31
 
32
 
 
 
 
 
 
 
 
 
 
 
33
  class ProgressFile(io.BufferedReader):
34
  """BufferedReader subclass that prints upload progress based on bytes read."""
35
 
@@ -50,10 +60,10 @@ class ProgressFile(io.BufferedReader):
50
  percent = int(self._seen * 100 / self._total_size)
51
  if percent != self._last_percent:
52
  self._last_percent = percent
53
- mb_seen = self._seen / (1024**2)
54
- mb_total = self._total_size / (1024**2)
55
  print(
56
- f"\rProgress: {percent:3d}% ({mb_seen:.2f} / {mb_total:.2f} MB)",
57
  end="",
58
  flush=True,
59
  )
 
30
  from huggingface_hub import HfHubError as HfHubHTTPError # type: ignore[assignment]
31
 
32
 
33
+ def _format_size(num_bytes: int) -> str:
34
+ """Return human-readable size with automatic units."""
35
+ units = ["B", "KB", "MB", "GB", "TB"]
36
+ size = float(num_bytes)
37
+ for unit in units:
38
+ if size < 1024.0 or unit == units[-1]:
39
+ return f"{size:.2f} {unit}"
40
+ size /= 1024.0
41
+
42
+
43
  class ProgressFile(io.BufferedReader):
44
  """BufferedReader subclass that prints upload progress based on bytes read."""
45
 
 
60
  percent = int(self._seen * 100 / self._total_size)
61
  if percent != self._last_percent:
62
  self._last_percent = percent
63
+ seen_str = _format_size(self._seen)
64
+ total_str = _format_size(self._total_size)
65
  print(
66
+ f"\rProgress: {percent:3d}% ({seen_str} / {total_str})",
67
  end="",
68
  flush=True,
69
  )