Datasets:
Upload folder using huggingface_hub
Browse files- dataset.py +32 -0
dataset.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
class DatasetConfig(datasets.BuilderConfig):
|
5 |
+
def __init__(self, **kwargs):
|
6 |
+
super().__init__(**kwargs)
|
7 |
+
|
8 |
+
class DatasetBuilder(datasets.GeneratorBasedBuilder):
|
9 |
+
BUILDER_CONFIGS = [DatasetConfig(name="default", version=datasets.Version("1.0.0"))]
|
10 |
+
|
11 |
+
def _info(self):
|
12 |
+
return datasets.DatasetInfo(
|
13 |
+
features=datasets.Features({
|
14 |
+
"path": datasets.Value("string"),
|
15 |
+
"content": datasets.Value("string"), # Adjust to your actual CSV structure
|
16 |
+
}),
|
17 |
+
)
|
18 |
+
|
19 |
+
def _split_generators(self, dl_manager):
|
20 |
+
data_path = dl_manager.download("A_python_files_elaborated_metadata.csv")
|
21 |
+
return [
|
22 |
+
datasets.SplitGenerator(
|
23 |
+
name=datasets.Split.TRAIN,
|
24 |
+
gen_kwargs={"filepath": data_path},
|
25 |
+
)
|
26 |
+
]
|
27 |
+
|
28 |
+
def _generate_examples(self, filepath):
|
29 |
+
with open(filepath, encoding="utf-8") as f:
|
30 |
+
reader = csv.DictReader(f)
|
31 |
+
for idx, row in enumerate(reader):
|
32 |
+
yield idx, row
|