We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
AttributeError: type object 'tqdm' has no attribute '_lock'
### Describe the bug

Getting a tqdm issue when writing a Dask dataframe to the hub.

Similar to huggingface/datasets#6066. Using latest Datasets version doesn't seem to resolve it

### Steps to reproduce the bug

This is a minimal reproducer:
```
import dask.dataframe as dd
import pandas as pd
import random

import huggingface_hub

data = {"number": [random.randint(0,10) for _ in range(1000)]}
df = pd.DataFrame.from_dict(data)
dataframe = dd.from_pandas(df, npartitions=1)
dataframe = dataframe.repartition(npartitions=2)

repo_id = "nielsr/test-dask"
repo_path = f"hf://datasets/{repo_id}"
huggingface_hub.create_repo(repo_id=repo_id, repo_type="dataset", exist_ok=True)
dd.to_parquet(dataframe, path=f"{repo_path}/data")
```
Note: I'm intentionally repartioning the Dask dataframe to 2 partitions, as it does work when only having one partition. 

### Expected behavior

Would expect to write to the hub without any problem.

### Environment info

Datasets version 2.14.4

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/huggingface_hub/utils/tqdm.py`
Content:
```
1 #!/usr/bin/env python
2 # coding=utf-8
3 # Copyright 2021 The HuggingFace Inc. team. All rights reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License
16 """Utility helpers to handle progress bars in `huggingface_hub`.
17 
18 Example:
19     1. Use `huggingface_hub.utils.tqdm` as you would use `tqdm.tqdm` or `tqdm.auto.tqdm`.
20     2. To disable progress bars, either use `disable_progress_bars()` helper or set the
21        environment variable `HF_HUB_DISABLE_PROGRESS_BARS` to 1.
22     3. To re-enable progress bars, use `enable_progress_bars()`.
23     4. To check whether progress bars are disabled, use `are_progress_bars_disabled()`.
24 
25 NOTE: Environment variable `HF_HUB_DISABLE_PROGRESS_BARS` has the priority.
26 
27 Example:
28     ```py
29     from huggingface_hub.utils import (
30         are_progress_bars_disabled,
31         disable_progress_bars,
32         enable_progress_bars,
33         tqdm,
34     )
35 
36     # Disable progress bars globally
37     disable_progress_bars()
38 
39     # Use as normal `tqdm`
40     for _ in tqdm(range(5)):
41        do_something()
42 
43     # Still not showing progress bars, as `disable=False` is overwritten to `True`.
44     for _ in tqdm(range(5), disable=False):
45        do_something()
46 
47     are_progress_bars_disabled() # True
48 
49     # Re-enable progress bars globally
50     enable_progress_bars()
51 
52     # Progress bar will be shown !
53     for _ in tqdm(range(5)):
54        do_something()
55     ```
56 """
57 import io
58 import warnings
59 from contextlib import contextmanager
60 from pathlib import Path
61 from typing import Iterator, Optional, Union
62 
63 from tqdm.auto import tqdm as old_tqdm
64 
65 from ..constants import HF_HUB_DISABLE_PROGRESS_BARS
66 
67 
68 # `HF_HUB_DISABLE_PROGRESS_BARS` is `Optional[bool]` while `_hf_hub_progress_bars_disabled`
69 # is a `bool`. If `HF_HUB_DISABLE_PROGRESS_BARS` is set to True or False, it has priority.
70 # If `HF_HUB_DISABLE_PROGRESS_BARS` is None, it means the user have not set the
71 # environment variable and is free to enable/disable progress bars programmatically.
72 # TL;DR: env variable has priority over code.
73 #
74 # By default, progress bars are enabled.
75 _hf_hub_progress_bars_disabled: bool = HF_HUB_DISABLE_PROGRESS_BARS or False
76 
77 
78 def disable_progress_bars() -> None:
79     """
80     Disable globally progress bars used in `huggingface_hub` except if `HF_HUB_DISABLE_PROGRESS_BARS` environment
81     variable has been set.
82 
83     Use [`~utils.enable_progress_bars`] to re-enable them.
84     """
85     if HF_HUB_DISABLE_PROGRESS_BARS is False:
86         warnings.warn(
87             "Cannot disable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=0` is set and has"
88             " priority."
89         )
90         return
91     global _hf_hub_progress_bars_disabled
92     _hf_hub_progress_bars_disabled = True
93 
94 
95 def enable_progress_bars() -> None:
96     """
97     Enable globally progress bars used in `huggingface_hub` except if `HF_HUB_DISABLE_PROGRESS_BARS` environment
98     variable has been set.
99 
100     Use [`~utils.disable_progress_bars`] to disable them.
101     """
102     if HF_HUB_DISABLE_PROGRESS_BARS is True:
103         warnings.warn(
104             "Cannot enable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=1` is set and has"
105             " priority."
106         )
107         return
108     global _hf_hub_progress_bars_disabled
109     _hf_hub_progress_bars_disabled = False
110 
111 
112 def are_progress_bars_disabled() -> bool:
113     """Return whether progress bars are globally disabled or not.
114 
115     Progress bars used in `huggingface_hub` can be enable or disabled globally using [`~utils.enable_progress_bars`]
116     and [`~utils.disable_progress_bars`] or by setting `HF_HUB_DISABLE_PROGRESS_BARS` as environment variable.
117     """
118     global _hf_hub_progress_bars_disabled
119     return _hf_hub_progress_bars_disabled
120 
121 
122 class tqdm(old_tqdm):
123     """
124     Class to override `disable` argument in case progress bars are globally disabled.
125 
126     Taken from https://github.com/tqdm/tqdm/issues/619#issuecomment-619639324.
127     """
128 
129     def __init__(self, *args, **kwargs):
130         if are_progress_bars_disabled():
131             kwargs["disable"] = True
132         super().__init__(*args, **kwargs)
133 
134 
135 @contextmanager
136 def tqdm_stream_file(path: Union[Path, str]) -> Iterator[io.BufferedReader]:
137     """
138     Open a file as binary and wrap the `read` method to display a progress bar when it's streamed.
139 
140     First implemented in `transformers` in 2019 but removed when switched to git-lfs. Used in `huggingface_hub` to show
141     progress bar when uploading an LFS file to the Hub. See github.com/huggingface/transformers/pull/2078#discussion_r354739608
142     for implementation details.
143 
144     Note: currently implementation handles only files stored on disk as it is the most common use case. Could be
145           extended to stream any `BinaryIO` object but we might have to debug some corner cases.
146 
147     Example:
148     ```py
149     >>> with tqdm_stream_file("config.json") as f:
150     >>>     requests.put(url, data=f)
151     config.json: 100%|█████████████████████████| 8.19k/8.19k [00:02<00:00, 3.72kB/s]
152     ```
153     """
154     if isinstance(path, str):
155         path = Path(path)
156 
157     with path.open("rb") as f:
158         total_size = path.stat().st_size
159         pbar = tqdm(
160             unit="B",
161             unit_scale=True,
162             total=total_size,
163             initial=0,
164             desc=path.name,
165         )
166 
167         f_read = f.read
168 
169         def _inner_read(size: Optional[int] = -1) -> bytes:
170             data = f_read(size)
171             pbar.update(len(data))
172             return data
173 
174         f.read = _inner_read  # type: ignore
175 
176         yield f
177 
178         pbar.close()
179
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/huggingface_hub/utils/tqdm.py b/src/huggingface_hub/utils/tqdm.py
--- a/src/huggingface_hub/utils/tqdm.py
+++ b/src/huggingface_hub/utils/tqdm.py
@@ -131,6 +131,14 @@
             kwargs["disable"] = True
         super().__init__(*args, **kwargs)
 
+    def __delattr__(self, attr: str) -> None:
+        """Fix for https://github.com/huggingface/huggingface_hub/issues/1603"""
+        try:
+            super().__delattr__(attr)
+        except AttributeError:
+            if attr != "_lock":
+                raise
+
 
 @contextmanager
 def tqdm_stream_file(path: Union[Path, str]) -> Iterator[io.BufferedReader]:

{"golden_diff": "diff --git a/src/huggingface_hub/utils/tqdm.py b/src/huggingface_hub/utils/tqdm.py\n--- a/src/huggingface_hub/utils/tqdm.py\n+++ b/src/huggingface_hub/utils/tqdm.py\n@@ -131,6 +131,14 @@\n             kwargs[\"disable\"] = True\n         super().__init__(*args, **kwargs)\n \n+    def __delattr__(self, attr: str) -> None:\n+        \"\"\"Fix for https://github.com/huggingface/huggingface_hub/issues/1603\"\"\"\n+        try:\n+            super().__delattr__(attr)\n+        except AttributeError:\n+            if attr != \"_lock\":\n+                raise\n+\n \n @contextmanager\n def tqdm_stream_file(path: Union[Path, str]) -> Iterator[io.BufferedReader]:\n", "issue": "AttributeError: type object 'tqdm' has no attribute '_lock'\n### Describe the bug\r\n\r\nGetting a tqdm issue when writing a Dask dataframe to the hub.\r\n\r\nSimilar to huggingface/datasets#6066. Using latest Datasets version doesn't seem to resolve it\r\n\r\n### Steps to reproduce the bug\r\n\r\nThis is a minimal reproducer:\r\n```\r\nimport dask.dataframe as dd\r\nimport pandas as pd\r\nimport random\r\n\r\nimport huggingface_hub\r\n\r\ndata = {\"number\": [random.randint(0,10) for _ in range(1000)]}\r\ndf = pd.DataFrame.from_dict(data)\r\ndataframe = dd.from_pandas(df, npartitions=1)\r\ndataframe = dataframe.repartition(npartitions=2)\r\n\r\nrepo_id = \"nielsr/test-dask\"\r\nrepo_path = f\"hf://datasets/{repo_id}\"\r\nhuggingface_hub.create_repo(repo_id=repo_id, repo_type=\"dataset\", exist_ok=True)\r\ndd.to_parquet(dataframe, path=f\"{repo_path}/data\")\r\n```\r\nNote: I'm intentionally repartioning the Dask dataframe to 2 partitions, as it does work when only having one partition. \r\n\r\n### Expected behavior\r\n\r\nWould expect to write to the hub without any problem.\r\n\r\n### Environment info\r\n\r\nDatasets version 2.14.4\n", "before_files": [{"content": "#!/usr/bin/env python\n# coding=utf-8\n# Copyright 2021 The HuggingFace Inc. team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License\n\"\"\"Utility helpers to handle progress bars in `huggingface_hub`.\n\nExample:\n    1. Use `huggingface_hub.utils.tqdm` as you would use `tqdm.tqdm` or `tqdm.auto.tqdm`.\n    2. To disable progress bars, either use `disable_progress_bars()` helper or set the\n       environment variable `HF_HUB_DISABLE_PROGRESS_BARS` to 1.\n    3. To re-enable progress bars, use `enable_progress_bars()`.\n    4. To check whether progress bars are disabled, use `are_progress_bars_disabled()`.\n\nNOTE: Environment variable `HF_HUB_DISABLE_PROGRESS_BARS` has the priority.\n\nExample:\n    ```py\n    from huggingface_hub.utils import (\n        are_progress_bars_disabled,\n        disable_progress_bars,\n        enable_progress_bars,\n        tqdm,\n    )\n\n    # Disable progress bars globally\n    disable_progress_bars()\n\n    # Use as normal `tqdm`\n    for _ in tqdm(range(5)):\n       do_something()\n\n    # Still not showing progress bars, as `disable=False` is overwritten to `True`.\n    for _ in tqdm(range(5), disable=False):\n       do_something()\n\n    are_progress_bars_disabled() # True\n\n    # Re-enable progress bars globally\n    enable_progress_bars()\n\n    # Progress bar will be shown !\n    for _ in tqdm(range(5)):\n       do_something()\n    ```\n\"\"\"\nimport io\nimport warnings\nfrom contextlib import contextmanager\nfrom pathlib import Path\nfrom typing import Iterator, Optional, Union\n\nfrom tqdm.auto import tqdm as old_tqdm\n\nfrom ..constants import HF_HUB_DISABLE_PROGRESS_BARS\n\n\n# `HF_HUB_DISABLE_PROGRESS_BARS` is `Optional[bool]` while `_hf_hub_progress_bars_disabled`\n# is a `bool`. If `HF_HUB_DISABLE_PROGRESS_BARS` is set to True or False, it has priority.\n# If `HF_HUB_DISABLE_PROGRESS_BARS` is None, it means the user have not set the\n# environment variable and is free to enable/disable progress bars programmatically.\n# TL;DR: env variable has priority over code.\n#\n# By default, progress bars are enabled.\n_hf_hub_progress_bars_disabled: bool = HF_HUB_DISABLE_PROGRESS_BARS or False\n\n\ndef disable_progress_bars() -> None:\n    \"\"\"\n    Disable globally progress bars used in `huggingface_hub` except if `HF_HUB_DISABLE_PROGRESS_BARS` environment\n    variable has been set.\n\n    Use [`~utils.enable_progress_bars`] to re-enable them.\n    \"\"\"\n    if HF_HUB_DISABLE_PROGRESS_BARS is False:\n        warnings.warn(\n            \"Cannot disable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=0` is set and has\"\n            \" priority.\"\n        )\n        return\n    global _hf_hub_progress_bars_disabled\n    _hf_hub_progress_bars_disabled = True\n\n\ndef enable_progress_bars() -> None:\n    \"\"\"\n    Enable globally progress bars used in `huggingface_hub` except if `HF_HUB_DISABLE_PROGRESS_BARS` environment\n    variable has been set.\n\n    Use [`~utils.disable_progress_bars`] to disable them.\n    \"\"\"\n    if HF_HUB_DISABLE_PROGRESS_BARS is True:\n        warnings.warn(\n            \"Cannot enable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=1` is set and has\"\n            \" priority.\"\n        )\n        return\n    global _hf_hub_progress_bars_disabled\n    _hf_hub_progress_bars_disabled = False\n\n\ndef are_progress_bars_disabled() -> bool:\n    \"\"\"Return whether progress bars are globally disabled or not.\n\n    Progress bars used in `huggingface_hub` can be enable or disabled globally using [`~utils.enable_progress_bars`]\n    and [`~utils.disable_progress_bars`] or by setting `HF_HUB_DISABLE_PROGRESS_BARS` as environment variable.\n    \"\"\"\n    global _hf_hub_progress_bars_disabled\n    return _hf_hub_progress_bars_disabled\n\n\nclass tqdm(old_tqdm):\n    \"\"\"\n    Class to override `disable` argument in case progress bars are globally disabled.\n\n    Taken from https://github.com/tqdm/tqdm/issues/619#issuecomment-619639324.\n    \"\"\"\n\n    def __init__(self, *args, **kwargs):\n        if are_progress_bars_disabled():\n            kwargs[\"disable\"] = True\n        super().__init__(*args, **kwargs)\n\n\n@contextmanager\ndef tqdm_stream_file(path: Union[Path, str]) -> Iterator[io.BufferedReader]:\n    \"\"\"\n    Open a file as binary and wrap the `read` method to display a progress bar when it's streamed.\n\n    First implemented in `transformers` in 2019 but removed when switched to git-lfs. Used in `huggingface_hub` to show\n    progress bar when uploading an LFS file to the Hub. See github.com/huggingface/transformers/pull/2078#discussion_r354739608\n    for implementation details.\n\n    Note: currently implementation handles only files stored on disk as it is the most common use case. Could be\n          extended to stream any `BinaryIO` object but we might have to debug some corner cases.\n\n    Example:\n    ```py\n    >>> with tqdm_stream_file(\"config.json\") as f:\n    >>>     requests.put(url, data=f)\n    config.json: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 8.19k/8.19k [00:02<00:00, 3.72kB/s]\n    ```\n    \"\"\"\n    if isinstance(path, str):\n        path = Path(path)\n\n    with path.open(\"rb\") as f:\n        total_size = path.stat().st_size\n        pbar = tqdm(\n            unit=\"B\",\n            unit_scale=True,\n            total=total_size,\n            initial=0,\n            desc=path.name,\n        )\n\n        f_read = f.read\n\n        def _inner_read(size: Optional[int] = -1) -> bytes:\n            data = f_read(size)\n            pbar.update(len(data))\n            return data\n\n        f.read = _inner_read  # type: ignore\n\n        yield f\n\n        pbar.close()\n", "path": "src/huggingface_hub/utils/tqdm.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# coding=utf-8\n# Copyright 2021 The HuggingFace Inc. team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License\n\"\"\"Utility helpers to handle progress bars in `huggingface_hub`.\n\nExample:\n    1. Use `huggingface_hub.utils.tqdm` as you would use `tqdm.tqdm` or `tqdm.auto.tqdm`.\n    2. To disable progress bars, either use `disable_progress_bars()` helper or set the\n       environment variable `HF_HUB_DISABLE_PROGRESS_BARS` to 1.\n    3. To re-enable progress bars, use `enable_progress_bars()`.\n    4. To check whether progress bars are disabled, use `are_progress_bars_disabled()`.\n\nNOTE: Environment variable `HF_HUB_DISABLE_PROGRESS_BARS` has the priority.\n\nExample:\n    ```py\n    from huggingface_hub.utils import (\n        are_progress_bars_disabled,\n        disable_progress_bars,\n        enable_progress_bars,\n        tqdm,\n    )\n\n    # Disable progress bars globally\n    disable_progress_bars()\n\n    # Use as normal `tqdm`\n    for _ in tqdm(range(5)):\n       do_something()\n\n    # Still not showing progress bars, as `disable=False` is overwritten to `True`.\n    for _ in tqdm(range(5), disable=False):\n       do_something()\n\n    are_progress_bars_disabled() # True\n\n    # Re-enable progress bars globally\n    enable_progress_bars()\n\n    # Progress bar will be shown !\n    for _ in tqdm(range(5)):\n       do_something()\n    ```\n\"\"\"\nimport io\nimport warnings\nfrom contextlib import contextmanager\nfrom pathlib import Path\nfrom typing import Iterator, Optional, Union\n\nfrom tqdm.auto import tqdm as old_tqdm\n\nfrom ..constants import HF_HUB_DISABLE_PROGRESS_BARS\n\n\n# `HF_HUB_DISABLE_PROGRESS_BARS` is `Optional[bool]` while `_hf_hub_progress_bars_disabled`\n# is a `bool`. If `HF_HUB_DISABLE_PROGRESS_BARS` is set to True or False, it has priority.\n# If `HF_HUB_DISABLE_PROGRESS_BARS` is None, it means the user have not set the\n# environment variable and is free to enable/disable progress bars programmatically.\n# TL;DR: env variable has priority over code.\n#\n# By default, progress bars are enabled.\n_hf_hub_progress_bars_disabled: bool = HF_HUB_DISABLE_PROGRESS_BARS or False\n\n\ndef disable_progress_bars() -> None:\n    \"\"\"\n    Disable globally progress bars used in `huggingface_hub` except if `HF_HUB_DISABLE_PROGRESS_BARS` environment\n    variable has been set.\n\n    Use [`~utils.enable_progress_bars`] to re-enable them.\n    \"\"\"\n    if HF_HUB_DISABLE_PROGRESS_BARS is False:\n        warnings.warn(\n            \"Cannot disable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=0` is set and has\"\n            \" priority.\"\n        )\n        return\n    global _hf_hub_progress_bars_disabled\n    _hf_hub_progress_bars_disabled = True\n\n\ndef enable_progress_bars() -> None:\n    \"\"\"\n    Enable globally progress bars used in `huggingface_hub` except if `HF_HUB_DISABLE_PROGRESS_BARS` environment\n    variable has been set.\n\n    Use [`~utils.disable_progress_bars`] to disable them.\n    \"\"\"\n    if HF_HUB_DISABLE_PROGRESS_BARS is True:\n        warnings.warn(\n            \"Cannot enable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=1` is set and has\"\n            \" priority.\"\n        )\n        return\n    global _hf_hub_progress_bars_disabled\n    _hf_hub_progress_bars_disabled = False\n\n\ndef are_progress_bars_disabled() -> bool:\n    \"\"\"Return whether progress bars are globally disabled or not.\n\n    Progress bars used in `huggingface_hub` can be enable or disabled globally using [`~utils.enable_progress_bars`]\n    and [`~utils.disable_progress_bars`] or by setting `HF_HUB_DISABLE_PROGRESS_BARS` as environment variable.\n    \"\"\"\n    global _hf_hub_progress_bars_disabled\n    return _hf_hub_progress_bars_disabled\n\n\nclass tqdm(old_tqdm):\n    \"\"\"\n    Class to override `disable` argument in case progress bars are globally disabled.\n\n    Taken from https://github.com/tqdm/tqdm/issues/619#issuecomment-619639324.\n    \"\"\"\n\n    def __init__(self, *args, **kwargs):\n        if are_progress_bars_disabled():\n            kwargs[\"disable\"] = True\n        super().__init__(*args, **kwargs)\n\n    def __delattr__(self, attr: str) -> None:\n        \"\"\"Fix for https://github.com/huggingface/huggingface_hub/issues/1603\"\"\"\n        try:\n            super().__delattr__(attr)\n        except AttributeError:\n            if attr != \"_lock\":\n                raise\n\n\n@contextmanager\ndef tqdm_stream_file(path: Union[Path, str]) -> Iterator[io.BufferedReader]:\n    \"\"\"\n    Open a file as binary and wrap the `read` method to display a progress bar when it's streamed.\n\n    First implemented in `transformers` in 2019 but removed when switched to git-lfs. Used in `huggingface_hub` to show\n    progress bar when uploading an LFS file to the Hub. See github.com/huggingface/transformers/pull/2078#discussion_r354739608\n    for implementation details.\n\n    Note: currently implementation handles only files stored on disk as it is the most common use case. Could be\n          extended to stream any `BinaryIO` object but we might have to debug some corner cases.\n\n    Example:\n    ```py\n    >>> with tqdm_stream_file(\"config.json\") as f:\n    >>>     requests.put(url, data=f)\n    config.json: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 8.19k/8.19k [00:02<00:00, 3.72kB/s]\n    ```\n    \"\"\"\n    if isinstance(path, str):\n        path = Path(path)\n\n    with path.open(\"rb\") as f:\n        total_size = path.stat().st_size\n        pbar = tqdm(\n            unit=\"B\",\n            unit_scale=True,\n            total=total_size,\n            initial=0,\n            desc=path.name,\n        )\n\n        f_read = f.read\n\n        def _inner_read(size: Optional[int] = -1) -> bytes:\n            data = f_read(size)\n            pbar.update(len(data))\n            return data\n\n        f.read = _inner_read  # type: ignore\n\n        yield f\n\n        pbar.close()\n", "path": "src/huggingface_hub/utils/tqdm.py"}]}