samo-vecto commited on
Commit
7060de8
·
verified ·
1 Parent(s): aa1a993

Upload 2 files

Browse files
Files changed (2) hide show
  1. image-text-demo.py +58 -0
  2. images.tgz +3 -0
image-text-demo.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+
3
+ _CITATION = """\
4
+ @InProceedings{huggingface:dataset,
5
+ title = {nsfw image-text set},
6
+ author={Samvel Surmalyan},
7
+ year={2025}
8
+ }
9
+ """
10
+
11
+ _DESCRIPTION = """\
12
+ Demo dataset for testing or showing image-text capabilities.
13
+ """
14
+ _HOMEPAGE = "https://huggingface.co/datasets/samo-vecto/nsfw-images"
15
+
16
+ _LICENSE = ""
17
+
18
+ _REPO = "https://huggingface.co/datasets/samo-vecto/nsfw-images"
19
+
20
+ class ImageSet(datasets.GeneratorBasedBuilder):
21
+ """Small sample of image-text pairs"""
22
+
23
+ def _info(self):
24
+ return datasets.DatasetInfo(
25
+ description=_DESCRIPTION,
26
+ features=datasets.Features(
27
+ {
28
+ 'text': datasets.Value("string"),
29
+ 'image': datasets.Image(),
30
+ }
31
+ ),
32
+ supervised_keys=None,
33
+ homepage=_HOMEPAGE,
34
+ citation=_CITATION,
35
+ )
36
+
37
+ def _split_generators(self, dl_manager):
38
+ images_archive = dl_manager.download(f"{_REPO}/resolve/main/images.tgz")
39
+ image_iters = dl_manager.iter_archive(images_archive)
40
+ return [
41
+ datasets.SplitGenerator(
42
+ name=datasets.Split.TRAIN,
43
+ gen_kwargs={
44
+ "images": image_iters
45
+ }
46
+ ),
47
+ ]
48
+
49
+ def _generate_examples(self, images):
50
+ """ This function returns the examples in the raw (text) form."""
51
+
52
+ for idx, (filepath, image) in enumerate(images):
53
+ description = filepath.split('/')[-1][:-4]
54
+ description = description.replace('_', ' ')
55
+ yield idx, {
56
+ "image": {"path": filepath, "bytes": image.read()},
57
+ "text": description,
58
+ }
images.tgz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6d5896ecc970bad8b0605d2cedfff890a3de263d0118098896a42caf78bbbca
3
+ size 37837771