Skip to content

Commit b698915

Browse files
hoytakWauplin
andauthored
Update to use only summary bars for uploads when in notebooks (#3243)
* Update to use simple bar for notebook reporting. * Update to also deal with gui's, etc. * Updated style. * Update src/huggingface_hub/utils/_xet_progress_reporting.py Co-authored-by: Lucain <[email protected]> * Update src/huggingface_hub/utils/_xet_progress_reporting.py Co-authored-by: Lucain <[email protected]> * Update src/huggingface_hub/utils/_xet_progress_reporting.py Co-authored-by: Lucain <[email protected]> * Addressed PR feedback. * Update. * Update src/huggingface_hub/utils/tqdm.py * Update src/huggingface_hub/utils/tqdm.py --------- Co-authored-by: Lucain <[email protected]>
1 parent 3f2cf8e commit b698915

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/huggingface_hub/utils/_xet_progress_reporting.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@
33

44
from hf_xet import PyItemProgressUpdate, PyTotalProgressUpdate
55

6+
from . import is_google_colab, is_notebook
67
from .tqdm import tqdm
78

89

910
class XetProgressReporter:
10-
def __init__(self, n_lines: int = 10, description_width: int = 40):
11+
"""
12+
Reports on progress for Xet uploads.
13+
14+
Shows summary progress bars when running in notebooks or GUIs, and detailed per-file progress in console environments.
15+
"""
16+
17+
def __init__(self, n_lines: int = 10, description_width: int = 30):
1118
self.n_lines = n_lines
1219
self.description_width = description_width
1320

21+
self.per_file_progress = is_google_colab() or not is_notebook()
22+
1423
self.tqdm_settings = {
1524
"unit": "B",
1625
"unit_scale": True,
1726
"leave": True,
1827
"unit_divisor": 1000,
19-
"nrows": n_lines + 3,
28+
"nrows": n_lines + 3 if self.per_file_progress else 3,
2029
"miniters": 1,
2130
"bar_format": "{l_bar}{bar}| {n_fmt:>5}B / {total_fmt:>5}B{postfix:>12}",
2231
}
@@ -40,8 +49,13 @@ def __init__(self, n_lines: int = 10, description_width: int = 40):
4049
def format_desc(self, name: str, indent: bool) -> str:
4150
"""
4251
if name is longer than width characters, prints ... at the start and then the last width-3 characters of the name, otherwise
43-
the whole name right justified into 20 characters. Also adds some padding.
52+
the whole name right justified into description_width characters. Also adds some padding.
4453
"""
54+
55+
if not self.per_file_progress:
56+
# Here we just use the defaults.
57+
return name
58+
4559
padding = " " if indent else ""
4660
width = self.description_width - len(padding)
4761

@@ -74,6 +88,10 @@ def update_progress(self, total_update: PyTotalProgressUpdate, item_updates: Lis
7488
self.completed_items.add(name)
7589
new_completed.append(name)
7690

91+
# If we're only showing summary information, then don't update the individual bars
92+
if not self.per_file_progress:
93+
continue
94+
7795
# If we've run out of bars to use, then collapse the last ones together.
7896
if bar_idx >= len(self.current_bars):
7997
bar = self.current_bars[-1]
@@ -111,10 +129,11 @@ def update_progress(self, total_update: PyTotalProgressUpdate, item_updates: Lis
111129

112130
del self.item_state[name]
113131

114-
# Now manually refresh each of the bars
115-
for bar in self.current_bars:
116-
if bar:
117-
bar.refresh()
132+
if self.per_file_progress:
133+
# Now manually refresh each of the bars
134+
for bar in self.current_bars:
135+
if bar:
136+
bar.refresh()
118137

119138
# Update overall bars
120139
def postfix(speed):
@@ -136,6 +155,8 @@ def postfix(speed):
136155
def close(self, _success):
137156
self.data_processing_bar.close()
138157
self.upload_bar.close()
139-
for bar in self.current_bars:
140-
if bar:
141-
bar.close()
158+
159+
if self.per_file_progress:
160+
for bar in self.current_bars:
161+
if bar:
162+
bar.close()

0 commit comments

Comments
 (0)