chaturyaganne05 commited on
Commit
827e49a
1 Parent(s): 4713552

Upload filll50k.py

Browse files
Files changed (1) hide show
  1. filll50k.py +102 -0
filll50k.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from huggingface_hub import hf_hub_url
3
+ import datasets
4
+ import os
5
+
6
+ _VERSION = datasets.Version("0.0.2")
7
+
8
+ _DESCRIPTION = "Your dataset description here"
9
+ _HOMEPAGE = "Your dataset homepage URL here"
10
+ _LICENSE = "Your dataset license here"
11
+ _CITATION = "Your dataset citation here"
12
+
13
+ _FEATURES = datasets.Features(
14
+ {
15
+ "image": datasets.Image(),
16
+ "conditioning_image": datasets.Image(),
17
+ "text": datasets.Value("string"),
18
+ },
19
+ )
20
+
21
+ # Update these URLs to point to your dataset and images
22
+ METADATA_URL = hf_hub_url(
23
+ "chaturyaganne05/imgtovideo",
24
+ filename="dataset(1).json",
25
+ repo_type="dataset",
26
+ )
27
+
28
+ IMAGES_URL = hf_hub_url(
29
+ "chaturyaganne05/imgtovideo",
30
+ filename="images.zip",
31
+ repo_type="dataset",
32
+ )
33
+
34
+ CONDITIONING_IMAGES_URL = hf_hub_url(
35
+ "chaturyaganne05/imgtovideo",
36
+ filename="conditioning_images.zip",
37
+ repo_type="dataset",
38
+ )
39
+
40
+ _DEFAULT_CONFIG = datasets.BuilderConfig(name="default", version=_VERSION)
41
+
42
+ class Fill50k(datasets.GeneratorBasedBuilder):
43
+ BUILDER_CONFIGS = [_DEFAULT_CONFIG]
44
+ DEFAULT_CONFIG_NAME = "default"
45
+
46
+ def _info(self):
47
+ return datasets.DatasetInfo(
48
+ description=_DESCRIPTION,
49
+ features=_FEATURES,
50
+ supervised_keys=None,
51
+ homepage=_HOMEPAGE,
52
+ license=_LICENSE,
53
+ citation=_CITATION,
54
+ )
55
+
56
+ def _split_generators(self, dl_manager):
57
+ metadata_path = dl_manager.download(METADATA_URL)
58
+ images_dir = dl_manager.download_and_extract(IMAGES_URL)
59
+ conditioning_images_dir = dl_manager.download_and_extract(
60
+ CONDITIONING_IMAGES_URL
61
+ )
62
+
63
+ return [
64
+ datasets.SplitGenerator(
65
+ name=datasets.Split.TRAIN,
66
+ gen_kwargs={
67
+ "metadata_path": metadata_path,
68
+ "images_dir": images_dir,
69
+ "conditioning_images_dir": conditioning_images_dir,
70
+ },
71
+ ),
72
+ ]
73
+
74
+ def _generate_examples(self, metadata_path, images_dir, conditioning_images_dir):
75
+ metadata = pd.read_json(metadata_path, lines=True)
76
+
77
+ for _, row in metadata.iterrows():
78
+ text = row["text"]
79
+
80
+ image_path = row["image"]
81
+ image_path = os.path.join(images_dir, image_path)
82
+ with open(image_path, "rb") as img_file:
83
+ image = img_file.read()
84
+
85
+ conditioning_image_path = row["conditioning_image"]
86
+ conditioning_image_path = os.path.join(
87
+ conditioning_images_dir, conditioning_image_path
88
+ )
89
+ with open(conditioning_image_path, "rb") as cond_img_file:
90
+ conditioning_image = cond_img_file.read()
91
+
92
+ yield row["image"], {
93
+ "text": text,
94
+ "image": {
95
+ "path": image_path,
96
+ "bytes": image,
97
+ },
98
+ "conditioning_image": {
99
+ "path": conditioning_image_path,
100
+ "bytes": conditioning_image,
101
+ },
102
+ }