chavinlo commited on
Commit
793de29
1 Parent(s): 4da1594

Update test6.py

Browse files
Files changed (1) hide show
  1. test6.py +15 -9
test6.py CHANGED
@@ -3,17 +3,15 @@ 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
 
@@ -67,18 +65,26 @@ class FunkLoaderStream(datasets.GeneratorBasedBuilder):
67
  file_type = file_name.split('_')[0]
68
  file_id = file_name.split('_')[1].split('.')[0]
69
  file_ext = file_name.split('_')[1].split('.')[1]
70
- file_contents = tar.extractfile(file_info).read()
 
 
 
71
 
72
  # vis = video std; vim = video mean
73
  if file_type == 'txt' or file_type == 'vis' or file_type == 'vim':
 
 
 
 
 
74
  response_dict[file_id][file_type] = numpy.load(file_contents)
75
  elif file_type == 'jso':
76
- response_dict[file_id][file_type] = json.loads(file_contents)
77
 
78
  for key, value in response_dict.items():
79
  yield key, {
80
  "id": key,
81
- "metadata": value['jso'],
82
  "prompt": value['txt'],
83
  "vidmean": value['vim'],
84
  "vidstd": value['vis'],
 
3
  import numpy
4
  import tarfile
5
  import io
6
+ from io import BytesIO
7
 
8
  _FEATURES = datasets.Features(
9
  {
10
  "id": datasets.Value("string"),
11
+ "metadata": datasets.Value("string"),
12
  "prompt": datasets.Array3D(shape=(1, 77, 768), dtype="float32"),
13
+ "vidmean": datasets.Sequence(feature=datasets.Array3D(shape=(4, 64, 64), dtype="float32")),
14
+ "vidstd": datasets.Sequence(feature=datasets.Array3D(shape=(4, 64, 64), dtype="float32"))
 
 
 
 
15
  }
16
  )
17
 
 
65
  file_type = file_name.split('_')[0]
66
  file_id = file_name.split('_')[1].split('.')[0]
67
  file_ext = file_name.split('_')[1].split('.')[1]
68
+ file_contents = tar.extractfile(file_info)
69
+
70
+ if file_id not in response_dict:
71
+ response_dict[file_id] = {}
72
 
73
  # vis = video std; vim = video mean
74
  if file_type == 'txt' or file_type == 'vis' or file_type == 'vim':
75
+ #don't ask me why, it just works
76
+ _tmp = BytesIO()
77
+ _tmp.write(tar.extractfile(file_name).read())
78
+ _tmp.seek(0)
79
+ file_contents = _tmp
80
  response_dict[file_id][file_type] = numpy.load(file_contents)
81
  elif file_type == 'jso':
82
+ response_dict[file_id][file_type] = json.loads(file_contents.read())
83
 
84
  for key, value in response_dict.items():
85
  yield key, {
86
  "id": key,
87
+ "metadata": json.dumps(value['jso']),
88
  "prompt": value['txt'],
89
  "vidmean": value['vim'],
90
  "vidstd": value['vis'],