Download test.py from minnnnn/test: direct link, hf CLI and curl.
- Browser
- Download file 2.71 kB
-
https://huggingface.co/datasets/minnnnn/test/resolve/main/test.py
- Command line
-
hf download hf://datasets/minnnnn/test/test.py
-
curl -L -o test.py https://huggingface.co/datasets/minnnnn/test/resolve/main/test.py
2.71 kB
| import os | |
| import datasets | |
| import urllib.request | |
| import csv | |
| _CITATION = """\ | |
| @InProceedings{huggingface:dataset, | |
| title = {diffusion train set}, | |
| } | |
| """ | |
| _DESCRIPTION = """\ | |
| This is a dataset that image data and caption txt | |
| """ | |
| _HOMEPAGE = "" | |
| _LICENSE = "" | |
| _VERSION = "0.0.1" | |
| _URL = "data/" | |
| _URLS = { | |
| "train": _URL + 'train1_dataset.csv', | |
| "reg": _URL + 'reg1_dataset.csv', | |
| } | |
| task_list = [ | |
| "train", | |
| "reg", | |
| ] | |
| class taskConfig(datasets.BuilderConfig): | |
| def __init__(self, **kwargs): | |
| super().__init__(version=datasets.Version("1.0.0"), **kwargs) | |
| class imgdataset(datasets.GeneratorBasedBuilder): | |
| BUILDER_CONFIGS = [ | |
| taskConfig( | |
| name=task_name, | |
| ) | |
| for task_name in task_list | |
| ] | |
| def _info(self): | |
| features = datasets.Features( | |
| { | |
| "folder_name" : datasets.Value("string"), | |
| "Class_name": datasets.Value("string"), | |
| "file_name": datasets.Value("string"), | |
| "file_id": datasets.Value("string") | |
| } | |
| ) | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=features, | |
| supervised_keys=None, | |
| version=_VERSION, | |
| citation=_CITATION, | |
| ) | |
| def _split_generators(self, dl_manager: datasets.DownloadManager): | |
| downloaded_files = dl_manager.download_and_extract(_URLS) | |
| task_name = self.config.name | |
| return [ | |
| datasets.SplitGenerator(datasets.Split.TRAIN, { | |
| "filepath": downloaded_files[task_name] | |
| }), | |
| ] | |
| def _generate_examples(self, filepath): | |
| """This function returns the examples in the raw (text) form.""" | |
| with open(filepath, encoding="utf-8") as f: | |
| data = csv.DictReader(f) | |
| key = 0 | |
| for row in data: | |
| yield key, { | |
| "folder_name" : row['folder_name'], | |
| "Class_name": row['Class_name'], | |
| "file_name": row['file_name'], | |
| "file_id": row['file_id'] | |
| } | |
| folder_name = row['folder_name'] | |
| class_name =row['Class_name'] | |
| file_name = row['file_name'] | |
| url =row['file_id'] | |
| path = os.path.join('./',folder_name,class_name,file_name) | |
| folder = os.path.join('./',folder_name,class_name) | |
| if not os.path.isdir(folder): #폴더가 존재하지 않는다면 폴더 생성 | |
| os.makedirs(folder) | |
| urllib.request.urlretrieve(url, path) | |
| key += 1 | |