Datasets:
Download open_cortex_fx_v3.py from Standout/open-cortex-fx-v3: direct link, hf CLI and curl.
- Browser
- Download file 4.9 kB
-
https://huggingface.co/datasets/Standout/open-cortex-fx-v3/resolve/main/open_cortex_fx_v3.py
- Command line
-
hf download hf://datasets/Standout/open-cortex-fx-v3/open_cortex_fx_v3.py
-
curl -L -o open_cortex_fx_v3.py https://huggingface.co/datasets/Standout/open-cortex-fx-v3/resolve/main/open_cortex_fx_v3.py
4.9 kB
| """Open Cortex FX v3 Dataset.""" | |
| import csv | |
| import io | |
| import zipfile | |
| from pathlib import Path | |
| from typing import Iterator | |
| import datasets | |
| _DESCRIPTION = """\ | |
| Open Cortex FX v3 is a video dataset focusing on human manual labor and physical work activities. | |
| Each video has been carefully annotated to identify work-related content and categorized into specific labor types. | |
| """ | |
| _HOMEPAGE = "https://huggingface.co/datasets/Standout/open-cortex-fx-v3" | |
| _LICENSE = "Apache 2.0" | |
| _CITATION = """\ | |
| @dataset{open_cortex_fx_v3, | |
| title={Open Cortex FX v3: A Classified Dataset of Human Manual Labor}, | |
| author={Standout}, | |
| year={2024}, | |
| url={https://huggingface.co/datasets/Standout/open-cortex-fx-v3} | |
| } | |
| """ | |
| class OpenCortexFXv3(datasets.GeneratorBasedBuilder): | |
| """Open Cortex FX v3 Dataset.""" | |
| VERSION = datasets.Version("1.0.0") | |
| BUILDER_CONFIGS = [ | |
| datasets.BuilderConfig( | |
| name="default", | |
| version=VERSION, | |
| description="Open Cortex FX v3 dataset", | |
| ), | |
| ] | |
| DEFAULT_CONFIG_NAME = "default" | |
| def _info(self) -> datasets.DatasetInfo: | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=datasets.Features( | |
| { | |
| "name": datasets.Value("string"), | |
| "category": datasets.Value("string"), | |
| "split": datasets.Value("string"), | |
| "video": datasets.Value("binary"), | |
| } | |
| ), | |
| homepage=_HOMEPAGE, | |
| license=_LICENSE, | |
| citation=_CITATION, | |
| ) | |
| def _split_generators(self, dl_manager: datasets.DownloadManager): | |
| """Returns SplitGenerators.""" | |
| # Define splits based on available zip files | |
| # We'll create splits for final_0 through final_5 (can be extended) | |
| splits = [] | |
| for i in range(6): # We have 6 splits (final_0 through final_5) | |
| split_name = f"final_{i}" | |
| zip_url = f"https://huggingface.co/datasets/Standout/open-cortex-fx-v3/resolve/main/final_{i}.zip" | |
| try: | |
| zip_path = dl_manager.download(zip_url) | |
| if zip_path and Path(zip_path).exists(): | |
| splits.append( | |
| datasets.SplitGenerator( | |
| name=datasets.Split(split_name), | |
| gen_kwargs={"zip_path": Path(zip_path)}, | |
| ) | |
| ) | |
| except Exception: | |
| # Skip if file doesn't exist | |
| continue | |
| # If no splits found, return at least one to avoid errors | |
| if not splits: | |
| # Fallback: try to find any zip file | |
| data_dir = Path(dl_manager.download_and_extract("https://huggingface.co/datasets/Standout/open-cortex-fx-v3/tree/main")) | |
| zip_files = sorted(data_dir.glob("final_*.zip")) | |
| for zip_file in zip_files: | |
| split_name = zip_file.stem | |
| splits.append( | |
| datasets.SplitGenerator( | |
| name=datasets.Split(split_name), | |
| gen_kwargs={"zip_path": zip_file}, | |
| ) | |
| ) | |
| return splits | |
| def _generate_examples(self, zip_path: Path) -> Iterator[tuple[int, dict]]: | |
| """Yields examples.""" | |
| with zipfile.ZipFile(zip_path, "r") as z: | |
| # Read metadata | |
| try: | |
| with z.open("metadata.csv") as f: | |
| content = f.read().decode("utf-8") | |
| reader = csv.DictReader(io.StringIO(content)) | |
| metadata = list(reader) | |
| except KeyError: | |
| # If metadata.csv not found, skip this split | |
| return | |
| # Get split name from zip filename | |
| split_name = zip_path.stem | |
| for idx, row in enumerate(metadata): | |
| video_name = row["name"] | |
| category = row["category"] | |
| # Find video in zip - try different path formats | |
| video_paths = [ | |
| f"{category}/{video_name}", | |
| f"{category.replace(' ', '_')}/{video_name}", | |
| video_name, # Fallback to root | |
| ] | |
| video_data = None | |
| for video_path in video_paths: | |
| try: | |
| video_data = z.read(video_path) | |
| break | |
| except KeyError: | |
| continue | |
| if video_data: | |
| yield idx, { | |
| "name": video_name, | |
| "category": category, | |
| "split": split_name, | |
| "video": video_data, | |
| } | |