MCPcopy
hub / github.com/PDFMathTranslate/PDFMathTranslate / translate_file

Function translate_file

pdf2zh/gui.py:198–352  ·  view source on GitHub ↗

This function translates a PDF file from one language to another. Inputs: - file_type: The type of file to translate - file_input: The file to translate - link_input: The link to the file to translate - service: The translation service to use - lang_

(
    file_type,
    file_input,
    link_input,
    service,
    lang_from,
    lang_to,
    page_range,
    page_input,
    prompt,
    threads,
    skip_subset_fonts,
    ignore_cache,
    vfont,
    use_babeldoc,
    recaptcha_response,
    state,
    progress=gr.Progress(),
    *envs,
)

Source from the content-addressed store, hash-verified

196
197
198def translate_file(
199 file_type,
200 file_input,
201 link_input,
202 service,
203 lang_from,
204 lang_to,
205 page_range,
206 page_input,
207 prompt,
208 threads,
209 skip_subset_fonts,
210 ignore_cache,
211 vfont,
212 use_babeldoc,
213 recaptcha_response,
214 state,
215 progress=gr.Progress(),
216 *envs,
217):
218 """
219 This function translates a PDF file from one language to another.
220
221 Inputs:
222 - file_type: The type of file to translate
223 - file_input: The file to translate
224 - link_input: The link to the file to translate
225 - service: The translation service to use
226 - lang_from: The language to translate from
227 - lang_to: The language to translate to
228 - page_range: The range of pages to translate
229 - page_input: The input for the page range
230 - prompt: The custom prompt for the llm
231 - threads: The number of threads to use
232 - recaptcha_response: The reCAPTCHA response
233 - state: The state of the translation process
234 - progress: The progress bar
235 - envs: The environment variables
236
237 Returns:
238 - The translated file
239 - The translated file
240 - The translated file
241 - The progress bar
242 - The progress bar
243 - The progress bar
244 """
245 session_id = uuid.uuid4()
246 state["session_id"] = session_id
247 cancellation_event_map[session_id] = asyncio.Event()
248 # Translate PDF content using selected service.
249 if flag_demo and not verify_recaptcha(recaptcha_response):
250 raise gr.Error("reCAPTCHA fail")
251
252 progress(0, desc="Starting translation...")
253
254 output = Path("pdf2zh_files")
255 output.mkdir(parents=True, exist_ok=True)

Callers

nothing calls this directly

Calls 5

translateFunction · 0.90
verify_recaptchaFunction · 0.85
download_with_limitFunction · 0.85
babeldoc_translate_fileFunction · 0.85

Tested by

no test coverage detected