MCPcopy Create free account
hub / github.com/NatsUIJM/autoContents / post_process_levels

Function post_process_levels

mainprogress/determine_toc_levels.py:409–440  ·  view source on GitHub ↗
(output_path: Path)

Source from the content-addressed store, hash-verified

407 page_data = json.load(f)
408 if not page_data: continue
409
410 current_max_level = max(item.get("level", 0) for item in page_data)
411 if current_max_level < first_page_max_level:
412 level_diff = first_page_max_level - current_max_level
413 write_log(f"修正文件 {file.name}: 层级提升 {level_diff}")
414 for item in page_data:
415 item["level"] += level_diff
416 with open(file, 'w', encoding='utf-8') as f:
417 json.dump(page_data, f, ensure_ascii=False, indent=2)
418 except Exception as e:
419 write_log(f"后处理异常:{str(e)}")
420
421async def run_batch_processing(image_files: list, output_path: Path):
422 if not image_files:
423 return
424
425 write_log(f"正在预处理并缓存 {len(image_files)} 张图片...")
426 for img in image_files:
427 get_encoded_image(img)
428
429 semaphore = asyncio.Semaphore(CONCURRENT_LIMIT)
430
431 # 1. 串行处理第一张图片
432 first_img = image_files[0]
433 first_csv = output_path / f"{first_img.stem}.csv"
434
435 write_log("阶段 1: 处理首图以生成 Few-shot 示例 (CSV 格式)")
436 success = await process_first_page(first_img, first_csv, output_path)
437
438 if not success:
439 write_log("严重错误:首图处理失败,无法生成参考示例,终止后续并发处理。")
440 print("首图处理失败,脚本停止。请检查日志。")
441 return
442
443 # 2. 并发处理剩余图片

Callers 1

main_asyncFunction · 0.85

Calls 2

write_logFunction · 0.70
natural_sort_keyFunction · 0.70

Tested by

no test coverage detected