(yadt_config)
| 420 | ) |
| 421 | |
| 422 | async def yadt_translate_coro(yadt_config): |
| 423 | progress_context, progress_handler = create_progress_handler(yadt_config) |
| 424 | |
| 425 | # 开始翻译 |
| 426 | with progress_context: |
| 427 | async for event in babeldoc_translate(yadt_config): |
| 428 | progress_handler(event) |
| 429 | if yadt_config.debug: |
| 430 | logger.debug(event) |
| 431 | kwargs["callback"](progress_context) |
| 432 | if kwargs["cancellation_event"].is_set(): |
| 433 | yadt_config.cancel_translation() |
| 434 | raise CancelledError |
| 435 | if event["type"] == "finish": |
| 436 | result = event["translate_result"] |
| 437 | logger.info("Translation Result:") |
| 438 | logger.info(f" Original PDF: {result.original_pdf_path}") |
| 439 | logger.info(f" Time Cost: {result.total_seconds:.2f}s") |
| 440 | logger.info(f" Mono PDF: {result.mono_pdf_path or 'None'}") |
| 441 | logger.info(f" Dual PDF: {result.dual_pdf_path or 'None'}") |
| 442 | file_mono = result.mono_pdf_path |
| 443 | file_dual = result.dual_pdf_path |
| 444 | break |
| 445 | import gc |
| 446 | |
| 447 | gc.collect() |
| 448 | return ( |
| 449 | str(file_mono), |
| 450 | str(file_mono), |
| 451 | str(file_dual), |
| 452 | gr.update(visible=True), |
| 453 | gr.update(visible=True), |
| 454 | gr.update(visible=True), |
| 455 | ) |
| 456 | |
| 457 | return asyncio.run(yadt_translate_coro(yadt_config)) |
| 458 |
no outgoing calls
no test coverage detected