chavinlo commited on
Commit
fb852f9
1 Parent(s): 2c5292f

Create medium.py

Browse files
Files changed (1) hide show
  1. medium.py +100 -0
medium.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import json
3
+ import numpy
4
+ import tarfile
5
+ import io
6
+
7
+ _FEATURES = datasets.Features(
8
+ {
9
+ "id": datasets.Value("string"),
10
+ "prompt": datasets.Array3D(shape=(1, 77, 768), dtype="float32"),
11
+ "video": datasets.Sequence(feature=datasets.Array3D(shape=(4, 64, 64), dtype="float32")),
12
+ "description": datasets.Value("string"),
13
+ "videourl": datasets.Value("string"),
14
+ "categories": datasets.Value("string"),
15
+ "duration": datasets.Value("float"),
16
+ "full_metadata": datasets.Value("string"),
17
+ }
18
+ )
19
+
20
+ class FunkLoaderStream(datasets.GeneratorBasedBuilder):
21
+ """TempoFunk Dataset"""
22
+
23
+ def _info(self):
24
+ return datasets.DatasetInfo(
25
+ description="TempoFunk Dataset",
26
+ features=_FEATURES,
27
+ homepage="tempofunk.github.io",
28
+ citation="""
29
+ @misc{TempoFunk2023,
30
+ author = {Lopho, Carlos Chavez},
31
+ title = {TempoFunk: Extending latent diffusion image models to Video},
32
+ url = {tempofunk.github.io},
33
+ month = {5},
34
+ year = {2023}
35
+ }
36
+ """,
37
+ license="AGPL v3"
38
+ )
39
+
40
+ def _split_generators(self, dl_manager):
41
+ # Load the chunk list.
42
+ print("PATH:", dl_manager.download("lists/chunk_list.json"))
43
+ thing = json.load(open(dl_manager.download("lists/chunk_list.json"), 'rb'))
44
+ _CHUNK_LIST = thing
45
+
46
+ # Create a list to hold the downloaded chunks.
47
+ _list = []
48
+
49
+ # Download each chunk file.
50
+ for chunk in _CHUNK_LIST:
51
+ _list.append(dl_manager.download(f"data/{chunk}.tar"))
52
+
53
+ # Return the list of downloaded chunks.
54
+ return [
55
+ datasets.SplitGenerator(
56
+ name=datasets.Split.TRAIN,
57
+ gen_kwargs={
58
+ "chunks": _list,
59
+ },
60
+ ),
61
+ ]
62
+
63
+ def _generate_examples(self, chunks):
64
+ """Generate images and labels for splits."""
65
+ for chunk in chunks:
66
+ tar_data = open(chunk, 'rb')
67
+ tar_bytes = tar_data.read()
68
+ tar_bytes_io = io.BytesIO(tar_bytes)
69
+
70
+ response_dict = {}
71
+
72
+ with tarfile.open(fileobj=tar_bytes_io, mode='r') as tar:
73
+ for file_info in tar:
74
+ if file_info.isfile():
75
+ file_name = file_info.name
76
+ #filename format is typ_id.ext
77
+ file_type = file_name.split('_')[0]
78
+ file_id = file_name.split('_')[1].split('.')[0]
79
+ file_ext = file_name.split('_')[1].split('.')[1]
80
+ file_contents = tar.extractfile(file_info).read()
81
+
82
+ if file_id not in response_dict:
83
+ response_dict[file_id] = {}
84
+
85
+ if file_type == 'txt' or file_type == 'vid':
86
+ response_dict[file_id][file_type] = numpy.load(io.BytesIO(file_contents))
87
+ elif file_type == 'jso':
88
+ response_dict[file_id][file_type] = json.loads(file_contents)
89
+
90
+ for key, value in response_dict.items():
91
+ yield key, {
92
+ "id": key,
93
+ "description": value['jso']['description'],
94
+ "prompt": value['txt'],
95
+ "video": value['vid'],
96
+ "videourl": value['jso']['videourl'],
97
+ "categories": value['jso']['categories'],
98
+ "duration": value['jso']['duration'],
99
+ "full_metadata": value['jso']
100
+ }