科学 PDF 文書の翻訳およびバイリンガル比較ツール
- 📊 数式、チャート、目次、注釈を保持 (プレビュー)
- 🌐 複数の言語 と 多様な翻訳サービス をサポート
- 🤖 コマンドラインツール、インタラクティブユーザーインターフェース、および Docker を提供
フィードバックは GitHub Issues、Telegram グループ または QQ グループ でお気軽にどうぞ
- [2024年11月26日] CLIがオンラインファイルをサポートするようになりました (by @reycn)
- [2024年11月24日] 依存関係のサイズを削減するために ONNX サポートを追加しました (by @Wybxc)
- [2024年11月23日] 🌟 公共サービス がオンラインになりました! (by @Byaidu)
- [2024年11月23日] ウェブボットを防ぐためのファイアウォールを追加しました (by @Byaidu)
- [2024年11月22日] GUIがイタリア語をサポートし、改善されました (by @Byaidu, @reycn)
- [2024年11月22日] デプロイされたサービスを他の人と共有できるようになりました (by @Zxis233)
- [2024年11月22日] Tencent翻訳をサポートしました (by @hellofinch)
- [2024年11月21日] GUIがバイリンガルドキュメントのダウンロードをサポートするようになりました (by @reycn)
- [2024年11月20日] 🌟 デモ がオンラインになりました! (by @reycn)
無料サービス (https://pdf2zh.com/)
インストールなしで 公共サービス をオンラインで試すことができます。
インストールなしで HuggingFace上のデモ, ModelScope上のデモ を試すことができます。 デモの計算リソースは限られているため、乱用しないようにしてください。
このプロジェクトを使用するための4つの方法を提供しています:コマンドライン、ポータブル、GUI、および Docker。
pdf2zhの実行には追加モデル(wybxc/DocLayout-YOLO-DocStructBench-onnx)が必要です。このモデルはModelScopeでも見つけることができます。起動時にこのモデルのダウンロードに問題がある場合は、以下の環境変数を使用してください:
set HF_ENDPOINT=https://hf-mirror.com-
Pythonがインストールされていること (バージョン3.8 <= バージョン <= 3.12)
-
パッケージをインストールします:
pip install pdf2zh
-
翻訳を実行し、現在の作業ディレクトリ にファイルを生成します:
pdf2zh document.pdf
Python環境を事前にインストールする必要はありません
setup.bat をダウンロードしてダブルクリックして実行します
-
Pythonがインストールされていること (バージョン3.8 <= バージョン <= 3.12)
-
パッケージをインストールします:
pip install pdf2zh
-
ブラウザで使用を開始します:
pdf2zh -i
-
ブラウザが自動的に起動しない場合は、次のURLを開きます:
http://localhost:7860/
詳細については、GUIのドキュメント を参照してください。
-
プルして実行します:
docker pull byaidu/pdf2zh docker run -d -p 7860:7860 byaidu/pdf2zh
-
ブラウザで開きます:
http://localhost:7860/
クラウドサービスでのDockerデプロイメント用:
コマンドラインで翻訳コマンドを実行し、現在の作業ディレクトリに翻訳されたドキュメント example-mono.pdf とバイリンガルドキュメント example-dual.pdf を生成します。デフォルトではGoogle翻訳サービスを使用します。
以下の表に、参考のためにすべての高度なオプションをリストしました:
- 全文翻訳
pdf2zh example.pdf- 部分翻訳
pdf2zh example.pdf -p 1-3,5Google Languages Codes、DeepL Languages Codes を参照してください
pdf2zh example.pdf -li en -lo ja以下の表は、各翻訳サービスに必要な 環境変数 を示しています。各サービスを使用する前に、これらの変数を設定してください。
| Translator | Service | Environment Variables | Default Values | Notes |
|---|---|---|---|---|
| Google (Default) | google |
None | N/A | None |
| Bing | bing |
None | N/A | None |
| DeepL | deepl |
DEEPL_AUTH_KEY |
[Your Key] |
See DeepL |
| DeepLX | deeplx |
DEEPLX_ENDPOINT |
https://api.deepl.com/translate |
See DeepLX |
| Ollama | ollama |
OLLAMA_HOST, OLLAMA_MODEL |
http://127.0.0.1:11434, gemma2 |
See Ollama |
| OpenAI | openai |
OPENAI_BASE_URL, OPENAI_API_KEY, OPENAI_MODEL |
https://api.openai.com/v1, [Your Key], gpt-4o-mini |
See OpenAI |
| AzureOpenAI | azure-openai |
AZURE_OPENAI_BASE_URL, AZURE_OPENAI_API_KEY, AZURE_OPENAI_MODEL |
[Your Endpoint], [Your Key], gpt-4o-mini |
See Azure OpenAI |
| Zhipu | zhipu |
ZHIPU_API_KEY, ZHIPU_MODEL |
[Your Key], glm-4-flash |
See Zhipu |
| ModelScope | ModelScope |
MODELSCOPE_API_KEY, MODELSCOPE_MODEL |
[Your Key], Qwen/Qwen2.5-Coder-32B-Instruct |
See ModelScope |
| Silicon | silicon |
SILICON_API_KEY, SILICON_MODEL |
[Your Key], Qwen/Qwen2.5-7B-Instruct |
See SiliconCloud |
| Gemini | gemini |
GEMINI_API_KEY, GEMINI_MODEL |
[Your Key], gemini-1.5-flash |
See Gemini |
| Azure | azure |
AZURE_ENDPOINT, AZURE_API_KEY |
https://api.translator.azure.cn, [Your Key] |
See Azure |
| Tencent | tencent |
TENCENTCLOUD_SECRET_ID, TENCENTCLOUD_SECRET_KEY |
[Your ID], [Your Key] |
See Tencent |
| Dify | dify |
DIFY_API_URL, DIFY_API_KEY |
[Your DIFY URL], [Your Key] |
See Dify,Three variables, lang_out, lang_in, and text, need to be defined in Dify's workflow input. |
| AnythingLLM | anythingllm |
AnythingLLM_URL, AnythingLLM_APIKEY |
[Your AnythingLLM URL], [Your Key] |
See anything-llm |
-s service または -s service:model を使用してサービスを指定します:
pdf2zh example.pdf -s openai:gpt-4o-miniまたは環境変数でモデルを指定します:
set OPENAI_MODEL=gpt-4o-mini
pdf2zh example.pdf -s openai正規表現を使用して保持する必要がある数式フォントと文字を指定します:
pdf2zh example.pdf -f "(CM[^RT].*|MS.*|.*Ital)" -c "(\(|\||\)|\+|=|\d|[\u0080-\ufaff])"デフォルトで Latex、Mono、Code、Italic、Symbol および Math フォントを保持します:
pdf2zh example.pdf -f "(CM[^R]|(MS|XY|MT|BL|RM|EU|LA|RS)[A-Z]|LINE|LCIRCLE|TeX-|rsfs|txsy|wasy|stmary|.*Mono|.*Code|.*Ital|.*Sym|.*Math)"-t を使用して翻訳に使用するスレッド数を指定します:
pdf2zh example.pdf -t 1--promptを使用して、LLMで使用するプロンプトを指定します:
pdf2zh example.pdf -pr prompt.txtprompt.txtの例:
[
{
"role": "system",
"content": "You are a professional,authentic machine translation engine.",
},
{
"role": "user",
"content": "Translate the following markdown source text to ${lang_out}. Keep the formula notation {{v*}} unchanged. Output translation directly without any additional text.\nSource Text: ${text}\nTranslated Text:",
},
]カスタムプロンプトファイルでは、以下の3つの変数が使用できます。
from pdf2zh import translate, translate_stream
params = {"lang_in": "en", "lang_out": "zh", "service": "google", "thread": 4}
file_mono, file_dual = translate(files=["example.pdf"], **params)[0]
with open("example.pdf", "rb") as f:
stream_mono, stream_dual = translate_stream(stream=f.read(), **params)pip install pdf2zh[backend]
pdf2zh --flask
pdf2zh --celery workercurl http://localhost:11008/v1/translate -F "file=@example.pdf" -F "data={\"lang_in\":\"en\",\"lang_out\":\"zh\",\"service\":\"google\",\"thread\":4}"
{"id":"d9894125-2f4e-45ea-9d93-1a9068d2045a"}
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a
{"info":{"n":13,"total":506},"state":"PROGRESS"}
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a
{"state":"SUCCESS"}
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a/mono --output example-mono.pdf
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a/dual --output example-dual.pdf
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a -X DELETE-
ドキュメントのマージ:PyMuPDF
-
ドキュメントの解析:Pdfminer.six
-
ドキュメントの抽出:MinerU
-
ドキュメントプレビュー:Gradio PDF
-
マルチスレッド翻訳:MathTranslate
-
レイアウト解析:DocLayout-YOLO
-
ドキュメント標準:PDF Explained、PDF Cheat Sheets
-
多言語フォント:Go Noto Universal



