From f5502d73d5481b20aacfcb3df28963fb292ae643 Mon Sep 17 00:00:00 2001 From: xunbu Date: Fri, 9 May 2025 18:28:20 +0800 Subject: [PATCH] small fix --- .idea/workspace.xml | 17 ++++------------- README.md | 16 +++++++++------- docutranslate/translater.py | 12 ++++++++++-- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5841ad1..43121af 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,18 +5,9 @@ - - - - - - - - - - + - + @@ -377,7 +368,7 @@ - + @@ -388,7 +379,7 @@ - + diff --git a/README.md b/README.md index d492863..a20094d 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com' 以下操作会自动从[huggingface](https://huggingface.co)下载模型,windows需要使用**管理员模式**打开IDE运行脚本,并按需换源 -- 第一次读取非markdown文本 -- 第一次使用公式识别或代码识别功能 +- 第一次使用该库读取、翻译非markdown文本 +- 第一次使用该库的公式识别或代码识别功能 ## 翻译文件 @@ -120,11 +120,13 @@ translater.read_file("<文件路径>").save_as_markdown() ```python from docutranslate import FileTranslater -translater = FileTranslater(base_url="", - key="", - model_id="", # 使用的模型id - chunksize=4000, # 【可选】markdown分块长度,分块越大效果越好,不建议超过4096 - max_concurrent=6 # 【可选】并发数,受到ai平台并发量限制,如果文章很长建议适当加大到20以上 +translater = FileTranslater(base_url="",# 默认的模型baseurl + key="",#默认的模型api-key + model_id="", # 默认的模型id + chunksize=4000, # markdown分块长度,分块越大效果越好,不建议超过4096 + max_concurrent=6, # 并发数,受到ai平台并发量限制,如果文章很长建议适当加大到20以上 + docling_artifact=None, #使用提前下载好的docling模型 + tips=True#开场提示 ) ``` diff --git a/docutranslate/translater.py b/docutranslate/translater.py index a720f5a..bf3802d 100644 --- a/docutranslate/translater.py +++ b/docutranslate/translater.py @@ -12,7 +12,7 @@ from docutranslate.utils.markdown_utils import uris2placeholder, placeholder2_ur class FileTranslater: def __init__(self, file_path: Path | str | None = None, chunksize: int = 4096, base_url="", key=None, - model_id="", temperature=0.7, max_concurrent=6, docling_artifact: Path | str | None = None): + model_id="", temperature=0.7, max_concurrent=6, docling_artifact: Path | str | None = None,tips=True): if isinstance(file_path, str): file_path = Path(file_path) self.file_path: Path = file_path @@ -26,7 +26,15 @@ class FileTranslater: self.model_id: str = model_id self.temperature = temperature self.docling_artifact=docling_artifact - + if tips: + print(""" +======= +[docutranslate](https://github.com/xunbu/docutranslate) +>以下操作会自动从[huggingface](https://huggingface.co)下载模型,windows需要使用**管理员模式**打开IDE运行脚本,并按需换源 +- 第一次使用该库读取、翻译非markdown文本 +- 第一次使用该库的公式识别或代码识别功能 +======= +""") def _mask_uris_in_markdown(self): self.markdown = uris2placeholder(self.markdown, self._mask_dict) return self