MCPcopy Index your code
hub / github.com/PDFMathTranslate/PDFMathTranslate / translate_patch

Function translate_patch

pdf2zh/high_level.py:70–166  ·  view source on GitHub ↗
(
    inf: BinaryIO,
    pages: Optional[list[int]] = None,
    vfont: str = "",
    vchar: str = "",
    thread: int = 0,
    doc_zh: Document = None,
    lang_in: str = "",
    lang_out: str = "",
    service: str = "",
    noto_name: str = "",
    noto: Font = None,
    callback: object = None,
    cancellation_event: asyncio.Event = None,
    model: OnnxModel = None,
    envs: Dict = None,
    prompt: Template = None,
    ignore_cache: bool = False,
    **kwarg: Any,
)

Source from the content-addressed store, hash-verified

68
69
70def translate_patch(
71 inf: BinaryIO,
72 pages: Optional[list[int]] = None,
73 vfont: str = "",
74 vchar: str = "",
75 thread: int = 0,
76 doc_zh: Document = None,
77 lang_in: str = "",
78 lang_out: str = "",
79 service: str = "",
80 noto_name: str = "",
81 noto: Font = None,
82 callback: object = None,
83 cancellation_event: asyncio.Event = None,
84 model: OnnxModel = None,
85 envs: Dict = None,
86 prompt: Template = None,
87 ignore_cache: bool = False,
88 **kwarg: Any,
89) -> None:
90 rsrcmgr = PDFResourceManager()
91 layout = {}
92 device = TranslateConverter(
93 rsrcmgr,
94 vfont,
95 vchar,
96 thread,
97 layout,
98 lang_in,
99 lang_out,
100 service,
101 noto_name,
102 noto,
103 envs,
104 prompt,
105 ignore_cache,
106 )
107
108 assert device is not None
109 obj_patch = {}
110 interpreter = PDFPageInterpreterEx(rsrcmgr, device, obj_patch)
111 if pages:
112 total_pages = len(pages)
113 else:
114 total_pages = doc_zh.page_count
115
116 parser = PDFParser(inf)
117 doc = PDFDocument(parser)
118 with tqdm.tqdm(total=total_pages) as progress:
119 for pageno, page in enumerate(PDFPage.create_pages(doc)):
120 if cancellation_event and cancellation_event.is_set():
121 raise CancelledError("task cancelled")
122 if pages and (pageno not in pages):
123 continue
124 progress.update()
125 if callback:
126 callback(progress)
127 page.pageno = pageno

Callers 1

translate_streamFunction · 0.85

Calls 4

process_pageMethod · 0.95
TranslateConverterClass · 0.90
predictMethod · 0.45

Tested by

no test coverage detected