File size: 2,569 Bytes
1bd15a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c19163d
1bd15a2
 
 
 
 
 
 
 
 
478b5d0
1bd15a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c19163d
42ce10c
1bd15a2
 
eccf0b1
1bd15a2
eccf0b1
1bd15a2
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pandas as pd
from huggingface_hub import hf_hub_url, login
import datasets
import os

# ===============================
# Configuración general
# ===============================

_VERSION = datasets.Version("0.0.2")
_DESCRIPTION = "Dataset for training text-to-image diffusion models."
_HOMEPAGE = "https://huggingface.co/datasets/RowScripts/ExteriorAI-base"
_LICENSE = "TODO"  # Cambiar si tienes una licencia específica
_CITATION = "TODO"


# ===============================
# Definir Features
# ===============================

_FEATURES = datasets.Features({
    "file_name": datasets.Image(),  # Solo imagen
    "text": datasets.Value("string"),  # Solo texto
})

# ===============================
# Rutas de archivos en el Hub
# ===============================

METADATA_URL = hf_hub_url(
    "RowScripts/ExteriorAI-base",
    filename="metadata.jsonl",
    repo_type="dataset",
)

IMAGES_URL = hf_hub_url(
    "RowScripts/ExteriorAI-base",
    filename="images.zip",
    repo_type="dataset",
)

_DEFAULT_CONFIG = datasets.BuilderConfig(name="default", version=_VERSION)

# ===============================
# Clase del Dataset
# ===============================

class ExteriorAI(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [_DEFAULT_CONFIG]
    DEFAULT_CONFIG_NAME = "default"

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=_FEATURES,
            supervised_keys=None,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        metadata_path = dl_manager.download(METADATA_URL)
        images_dir = dl_manager.download_and_extract(IMAGES_URL)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "metadata_path": metadata_path,
                    "images_dir": images_dir,
                },
            ),
        ]

    def _generate_examples(self, metadata_path, images_dir):
        metadata = pd.read_json(metadata_path, lines=True)

        for _, row in metadata.iterrows():
            text = row["text"]

            image_path = row["file_name"]
            # image_path = os.path.join(images_dir, image_path)
            image = open(image_path, "rb").read()

            yield row["file_name"], {
                "text": text,
                "file_name": {
                    "path": image_path,
                    "bytes": image,
                },
            }