科学 PDF 文書の翻訳およびバイリンガル比較ツール
フィードバックは GitHub Issues、Telegram グループ または QQ グループ でお気軽にどうぞ
インストールなしで 公共サービス をオンラインで試すことができます。
インストールなしで HuggingFace上のデモ を試すことができます。 デモの計算リソースは限られているため、乱用しないようにしてください。
このプロジェクトを使用するための4つの方法を提供しています:コマンドライン、ポータブル、GUI、および Docker。
パッケージをインストールします:
pip install pdf2zh
翻訳を実行し、現在の作業ディレクトリ にファイルを生成します:
pdf2zh document.pdf
Python環境を事前にインストールする必要はありません
setup.bat をダウンロードしてダブルクリックして実行します
パッケージをインストールします:
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翻訳サービスを使用します。

以下の表に、参考のためにすべての高度なオプションをリストしました:
| オプション | 機能 | 例 |
|---|---|---|
| files | ローカルファイル | pdf2zh ~/local.pdf |
| links | オンラインファイル | pdf2zh http://arxiv.org/paper.pdf |
-i |
GUIに入る | pdf2zh -i |
-p |
部分的なドキュメント翻訳 | pdf2zh example.pdf -p 1 |
-li |
ソース言語 | pdf2zh example.pdf -li en |
-lo |
ターゲット言語 | pdf2zh example.pdf -lo zh |
-s |
翻訳サービス | pdf2zh example.pdf -s deepl |
-t |
マルチスレッド | pdf2zh example.pdf -t 1 |
-o |
出力ディレクトリ | pdf2zh example.pdf -o output |
-f, -c |
例外 | pdf2zh example.pdf -f "(MS.*)" |
--share |
[gradio公開リンクを取得] | pdf2zh -i --share |
-a |
[ウェブ認証とカスタム認証ページの追加] | pdf2zh -i -a users.txt [auth.html] |
全文翻訳
pdf2zh example.pdf
部分翻訳
pdf2zh example.pdf -p 1-3,5
Google 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
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 worker
curl 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
マルチスレッド翻訳:MathTranslate
レイアウト解析:DocLayout-YOLO
ドキュメント標準:PDF Explained、PDF Cheat Sheets
多言語フォント:Go Noto Universal