File size: 1,872 Bytes
f6579b5 fc74ca8 f6579b5 fc74ca8 f6579b5 954961e f6579b5 5ff56c3 15c7da9 f6579b5 b1af44d f6579b5 f9e8f7c 5ff56c3 f6579b5 5ff56c3 f6579b5 |
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 |
import datasets
_CITATION = """\
@InProceedings{huggingface:dataset,
title = {Small image-text set},
author={Plaban Nayak},
year={2023}
}
"""
_DESCRIPTION = """\
Demo dataset for testing or showing image-text capabilities.
"""
_HOMEPAGE = "https://huggingface.co/datasets/Plaban81/image-demo"
_LICENSE = ""
_REPO = "https://huggingface.co/datasets/Plaban81/image-demo"
_URL ="https://huggingface.co/datasets/Plaban81/image-demo/resolve/main/images.json.gz"
descriptions = ['kajol', 'kagna', 'nohra', 'aish', 'kareena', 'shakti']
#
class image_demo(datasets.GeneratorBasedBuilder):
"""Small sample of image-text pairs"""
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
'text': datasets.Value("string"),
'image': datasets.Image(),
}
),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
images_archive = dl_manager.download((_URL)
print(images_archive)
image_iters = dl_manager.iter_archive(images_archive)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"images": image_iters
}
),
]
def _generate_examples(self, images):
""" This function returns the examples in the raw (text) form."""
for idx, (filepath, image) in enumerate(images):
#description = filepath.split('/')[-1][:-4]
#description = description.replace('_', ' ')
yield idx, {
"image": {"path": filepath, "image": image.read()},
"text": descriptions[idx],
} |