File size: 1,662 Bytes
a1d4687
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import json
import os
from tqdm import tqdm

INPUT_JSON = "splice_segment_metadata.json"
OUTPUT_JSONL = "metadata.jsonl"

def convert_to_jsonl_ordered():
    """
    Converts the nested SPLICE JSON metadata into a flat, logically ordered
    JSON Lines file for a professional display in the Hugging Face Viewer.
    """
    print(f"--- Converting to logically ordered '{OUTPUT_JSONL}' ---")

    with open(INPUT_JSON, 'r') as f:
        data = json.load(f)

    with open(OUTPUT_JSONL, 'w') as f_out:
        for video_info in tqdm(data, desc="Processing video tasks"):
            for segment in video_info.get("segments", []):
                output_record = {
                    "file_name": segment.get("output_path", ""),
                    "video_id": video_info.get("video_id", ""),
                    "part": segment.get("part", -1),
                    "label": segment.get("label", ""),
                    "domain": video_info.get("Domain", ""),
                    "class": video_info.get("class", ""),
                    #"subset": video_info.get("subset", ""),
                    "start": segment.get("start", -1.0),
                    "end": segment.get("end", -1.0),
                    #"segment_id": segment.get("segment_id", ""),
                    "task_duration": video_info.get("duration", -1.0),
                    "video_url": video_info.get("video_url", ""),
                }
                f_out.write(json.dumps(output_record) + '\n')

    print("\n--- Conversion Complete! ---")
    print(f"Successfully created '{OUTPUT_JSONL}' with a professional column order.")

if __name__ == "__main__":
    convert_to_jsonl_ordered()