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

Function process_window

mainprogress/pdf_metadata_extractor.py:244–269  ·  view source on GitHub ↗
(start_p, end_p)

Source from the content-addressed store, hash-verified

242 raw_save_path = os.path.join(initial_data_dir, raw_filename)
243
244 b64_img = create_concat_image_b64(doc, start_p, end_p, save_path=img_save_path)
245 if not b64_img:
246 return start_p, end_p, None, None, None
247
248 raw_res = await fetch_toc_from_image(client, model, b64_img, start_p, end_p, raw_save_path)
249 toc_start, toc_end = parse_toc_json(raw_res)
250
251 detail_filename = f"toc_detail_{start_p}_{end_p}.json"
252 detail_save_path = os.path.join(initial_data_dir, detail_filename)
253 detail_data = {
254 "page_range": f"{start_p}-{end_p}",
255 "parsed_result": {"toc_start": toc_start, "toc_end": toc_end},
256 "raw_response": raw_res,
257 "image_saved_as": img_filename
258 }
259 with open(detail_save_path, 'w', encoding='utf-8') as f:
260 json.dump(detail_data, f, ensure_ascii=False, indent=2)
261
262 return start_p, end_p, toc_start, toc_end, raw_res
263
264 async def run_batch(start_page, end_page_limit):
265 """执行一个批次的滑动窗口扫描"""
266 windows = []
267 for i in range(start_page, end_page_limit, 2):
268 if i > total_pages:
269 break
270 windows.append((i, min(i + 3, total_pages)))
271
272 if not windows:

Callers 1

run_batchFunction · 0.85

Calls 3

create_concat_image_b64Function · 0.85
fetch_toc_from_imageFunction · 0.85
parse_toc_jsonFunction · 0.85

Tested by

no test coverage detected