diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b9c7096..866edb2 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -7,6 +7,7 @@
+
@@ -32,38 +33,38 @@
- {
+ "keyToString": {
+ "DefaultHtmlFileTemplate": "HTML File",
+ "JavaScript 调试.output.html (1).executor": "Run",
+ "JavaScript 调试.output.html.executor": "Run",
+ "JavaScript 调试.regex_中文.html.executor": "Run",
+ "JavaScript 调试.test2_英文.html.executor": "Run",
+ "ModuleVcsDetector.initialDetectionPerformed": "true",
+ "Python 测试.Python 测试 (markdown_mask.py 内).executor": "Run",
+ "Python 测试.markdown_mask.Test.test_basic_link_masking 的 Python 测试.executor": "Run",
+ "Python.PDFtranslater (1).executor": "Run",
+ "Python.PDFtranslater (2).executor": "Run",
+ "Python.agent_utils.executor": "Run",
+ "Python.convert.executor": "Run",
+ "Python.markdown_splitter.executor": "Run",
+ "Python.markdown_utils.executor": "Run",
+ "Python.test.executor": "Run",
+ "Python.test1.executor": "Run",
+ "Python.translater.executor": "Debug",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.git.unshallow": "true",
+ "git-widget-placeholder": "main",
+ "last_opened_file_path": "C:/Users/jxgm/Desktop/FileTranslate/tests/resource",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "Errors",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
@@ -303,7 +304,8 @@
-
+
+
@@ -313,7 +315,7 @@
-
+
diff --git a/README.md b/README.md
index bf46346..ff161da 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@
常见的大模型平台baseurl可见[常用baseurl](#常用baseurl)
# 使用方式
-## 使用默认参数翻译pdf
+## 翻译文件
```python
from docutranslate.translater import FileTranslater
@@ -31,6 +31,9 @@ translater.translate_pdf_file("", to_lang="中文")
# 开启公式、代码识别(需要下载更多模型)
translater.translate_pdf_file("", to_lang="中文",formula=True, code=True)
+
+#翻译markdown文件
+translater.translate_markdown_file("",to_lang="中文")
```
> 第一次使用时需要下载模型(约1G、使用公式、代码识别需要多约0.5G),请稍作等待
> 输出文件默认放在`./output`中
@@ -48,6 +51,17 @@ translate_agent = translater.create_translate_agent(baseurl="", key="
translater.translate_pdf_file(pdf_path="", to_lang="中文", refine_agent=refine_agent,
translate_agent=translate_agent)
```
+## 文件转换(pdf/markdown->markdown/html)
+```python
+from docutranslate import FileTranslater
+translater=FileTranslater(base_url="",
+ key="",
+ model_id="")
+#markdown转html
+translater.read_markdown("").save_as_html()
+#pdf转markdown
+translater.read_pdf_as_markdown("").save_as_markdown()
+```
## 参数说明
### 创建FileTranslate
diff --git a/docutranslate/translater.py b/docutranslate/translater.py
index 5e7d2cc..f25c739 100644
--- a/docutranslate/translater.py
+++ b/docutranslate/translater.py
@@ -97,10 +97,12 @@ hello, what's your name?
你好,你叫什么名字?\no_think""".format(to_lang)
return agent
- def read_pdf_as_markdown(self, pdf: Path | None = None, formula=False, code=False, save=False):
+ def read_pdf_as_markdown(self, pdf: Path |str|None = None, formula=False, code=False, save=False):
print("正在将pdf转换为markdown")
if pdf is None:
pdf = self.file_path
+ if isinstance(pdf,str):
+ pdf=Path(pdf)
self.markdown = pdf2markdown_embed_images(pdf, formula, code)
print("pdf已转换")
if save: