Plaban81 commited on
Commit
f6579b5
·
1 Parent(s): 66d2a00

Upload image_demo.py

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