Ishwar Balappanawar commited on
Commit ·
2d9c359
1
Parent(s): 59813c2
Normalize local filesystem handling
Browse files- cuebench.py +21 -0
cuebench.py
CHANGED
|
@@ -12,6 +12,7 @@ from datasets import (
|
|
| 12 |
Value,
|
| 13 |
Version,
|
| 14 |
)
|
|
|
|
| 15 |
|
| 16 |
HF_DATA_BASE_URL = "https://huggingface.co/datasets/ishwarbb23/cuebench/resolve/main"
|
| 17 |
DATA_BASE_OVERRIDE = os.getenv("CUEBENCH_DATA_BASE_URL")
|
|
@@ -112,3 +113,23 @@ class CUEBench(GeneratorBasedBuilder):
|
|
| 112 |
"target_classes": example["target_classes"],
|
| 113 |
}
|
| 114 |
idx += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
Value,
|
| 13 |
Version,
|
| 14 |
)
|
| 15 |
+
from fsspec.implementations.local import LocalFileSystem
|
| 16 |
|
| 17 |
HF_DATA_BASE_URL = "https://huggingface.co/datasets/ishwarbb23/cuebench/resolve/main"
|
| 18 |
DATA_BASE_OVERRIDE = os.getenv("CUEBENCH_DATA_BASE_URL")
|
|
|
|
| 113 |
"target_classes": example["target_classes"],
|
| 114 |
}
|
| 115 |
idx += 1
|
| 116 |
+
|
| 117 |
+
def _ensure_local_fs_protocol(self):
|
| 118 |
+
if isinstance(getattr(self, "_fs", None), LocalFileSystem):
|
| 119 |
+
protocol = getattr(self._fs, "protocol", None)
|
| 120 |
+
if protocol != "file":
|
| 121 |
+
self._fs.protocol = "file"
|
| 122 |
+
output_dir = getattr(self, "_output_dir", None)
|
| 123 |
+
if isinstance(output_dir, str):
|
| 124 |
+
stripped = self._fs._strip_protocol(output_dir)
|
| 125 |
+
if stripped:
|
| 126 |
+
self._output_dir = stripped
|
| 127 |
+
|
| 128 |
+
def _download_and_prepare(self, *args, **kwargs):
|
| 129 |
+
result = super()._download_and_prepare(*args, **kwargs)
|
| 130 |
+
self._ensure_local_fs_protocol()
|
| 131 |
+
return result
|
| 132 |
+
|
| 133 |
+
def as_dataset(self, *args, **kwargs):
|
| 134 |
+
self._ensure_local_fs_protocol()
|
| 135 |
+
return super().as_dataset(*args, **kwargs)
|