standoutw commited on
Commit
6eac4da
·
verified ·
1 Parent(s): b457b7a

Upload open_cortex_fx_v3.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. open_cortex_fx_v3.py +35 -39
open_cortex_fx_v3.py CHANGED
@@ -60,24 +60,20 @@ class OpenCortexFXv3(datasets.GeneratorBasedBuilder):
60
 
61
  def _split_generators(self, dl_manager: datasets.DownloadManager):
62
  """Returns SplitGenerators."""
63
- # Download all zip files
64
- zip_urls = [
65
- f"https://huggingface.co/datasets/Standout/open-cortex-fx-v3/resolve/main/final_{i}.zip"
66
- for i in range(10) # Support up to 10 splits
67
- ]
68
-
69
- zip_paths = dl_manager.download(zip_urls)
70
-
71
  splits = []
72
- for idx, zip_path in enumerate(zip_paths):
73
- if zip_path and Path(zip_path).exists():
74
- split_name = f"final_{idx}"
75
- splits.append(
76
- datasets.SplitGenerator(
77
- name=datasets.Split(split_name),
78
- gen_kwargs={"zip_path": Path(zip_path)},
79
- )
 
80
  )
 
81
 
82
  return splits
83
 
@@ -85,10 +81,14 @@ class OpenCortexFXv3(datasets.GeneratorBasedBuilder):
85
  """Yields examples."""
86
  with zipfile.ZipFile(zip_path, "r") as z:
87
  # Read metadata
88
- with z.open("metadata.csv") as f:
89
- content = f.read().decode("utf-8")
90
- reader = csv.DictReader(io.StringIO(content))
91
- metadata = list(reader)
 
 
 
 
92
 
93
  # Get split name from zip filename
94
  split_name = zip_path.stem
@@ -97,29 +97,25 @@ class OpenCortexFXv3(datasets.GeneratorBasedBuilder):
97
  video_name = row["name"]
98
  category = row["category"]
99
 
100
- # Find video in zip
101
- video_path_in_zip = f"{category}/{video_name}"
 
 
 
 
102
 
103
- try:
104
- video_data = z.read(video_path_in_zip)
 
 
 
 
 
 
 
105
  yield idx, {
106
  "name": video_name,
107
  "category": category,
108
  "split": split_name,
109
  "video": video_data,
110
  }
111
- except KeyError:
112
- # Try alternative path format
113
- video_path_in_zip = video_path_in_zip.replace(" ", "_")
114
- try:
115
- video_data = z.read(video_path_in_zip)
116
- yield idx, {
117
- "name": video_name,
118
- "category": category,
119
- "split": split_name,
120
- "video": video_data,
121
- }
122
- except KeyError:
123
- # Skip if video not found
124
- continue
125
-
 
60
 
61
  def _split_generators(self, dl_manager: datasets.DownloadManager):
62
  """Returns SplitGenerators."""
63
+ # Define splits based on available zip files
64
+ # We'll create splits for final_0 through final_5 (can be extended)
 
 
 
 
 
 
65
  splits = []
66
+ for i in range(6): # We have 6 splits (final_0 through final_5)
67
+ split_name = f"final_{i}"
68
+ zip_url = f"https://huggingface.co/datasets/Standout/open-cortex-fx-v3/resolve/main/final_{i}.zip"
69
+ zip_path = dl_manager.download(zip_url)
70
+
71
+ splits.append(
72
+ datasets.SplitGenerator(
73
+ name=datasets.Split(split_name),
74
+ gen_kwargs={"zip_path": Path(zip_path)},
75
  )
76
+ )
77
 
78
  return splits
79
 
 
81
  """Yields examples."""
82
  with zipfile.ZipFile(zip_path, "r") as z:
83
  # Read metadata
84
+ try:
85
+ with z.open("metadata.csv") as f:
86
+ content = f.read().decode("utf-8")
87
+ reader = csv.DictReader(io.StringIO(content))
88
+ metadata = list(reader)
89
+ except KeyError:
90
+ # If metadata.csv not found, skip this split
91
+ return
92
 
93
  # Get split name from zip filename
94
  split_name = zip_path.stem
 
97
  video_name = row["name"]
98
  category = row["category"]
99
 
100
+ # Find video in zip - try different path formats
101
+ video_paths = [
102
+ f"{category}/{video_name}",
103
+ f"{category.replace(' ', '_')}/{video_name}",
104
+ video_name, # Fallback to root
105
+ ]
106
 
107
+ video_data = None
108
+ for video_path in video_paths:
109
+ try:
110
+ video_data = z.read(video_path)
111
+ break
112
+ except KeyError:
113
+ continue
114
+
115
+ if video_data:
116
  yield idx, {
117
  "name": video_name,
118
  "category": category,
119
  "split": split_name,
120
  "video": video_data,
121
  }