Spaces:
Sleeping
Sleeping
File size: 1,554 Bytes
32b2277 432377b 32b2277 432377b 32b2277 432377b 32b2277 432377b 32b2277 432377b 32b2277 432377b 32b2277 432377b 32b2277 432377b 32b2277 432377b 32b2277 432377b 32b2277 432377b 32b2277 |
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 42 43 44 45 46 47 |
# import os
# import json
# import re
# from modules import outliner_dir, output_dir
# # ---------- Helper: sanitize file names ----------
# def safe_filename(name: str) -> str:
# return re.sub(r'[\\/*?:"<>|]', "", name).strip()
# # ---------- Main function ----------
# def split_json(input_file: str, output_dir: str):
# # Load JSON
# with open(input_file, "r", encoding="utf-8") as f:
# data = json.load(f)
# main_headings = data.get("main_headings", [])
# sub_headings = data.get("sub_headings", [])
# sub_sub_headings = data.get("sub_sub_headings", None)
# # Ensure output folder exists
# os.makedirs(output_dir, exist_ok=True)
# for idx, main in enumerate(main_headings):
# headers = sub_headings[idx] if idx < len(sub_headings) else []
# # ูู ููู sub_sub_headings ูุฌูุจูุงุ ูู ู
ุด ููู ูุฎูููุง null
# if sub_sub_headings and idx < len(sub_sub_headings):
# subs = sub_sub_headings[idx]
# else:
# subs = None
# section = {"headers": headers, "sub_sub_headings": subs}
# file_name = safe_filename(main) + ".json"
# file_path = os.path.join(output_dir, file_name)
# with open(file_path, "w", encoding="utf-8") as out_f:
# json.dump(section, out_f, ensure_ascii=False, indent=2)
# print(f"โ
Saved {file_name}")
# # ---------- Example usage ----------
# if __name__ == "__main__":
# split_json("/content/ai_agent_output/step_1_outlines.json", "output_sections")
|