Back to Pdfmathtranslate

README Ja JP

docs/README_ja-JP.md

1.9.1118.3 KB
Original Source
<div align="center">

English | 简体中文 | 繁體中文 | 日本語

<h2 id="title">PDFMathTranslate</h2> <p> <!-- PyPI --> <a href="https://pypi.org/project/pdf2zh/"> </a> <a href="https://pepy.tech/projects/pdf2zh"> </a> <a href="https://hub.docker.com/repository/docker/byaidu/pdf2zh"> </a> <!-- License --> <a href="./LICENSE"> </a> <a href="https://huggingface.co/spaces/reycn/PDFMathTranslate-Docker"> </a> <a href="https://www.modelscope.cn/studios/AI-ModelScope/PDFMathTranslate"> </a> <a href="https://github.com/Byaidu/PDFMathTranslate/pulls"> </a> <a href="https://gitcode.com/Byaidu/PDFMathTranslate/overview"> </a> <a href="https://t.me/+Z9_SgnxmsmA5NzBl"> </a> </p>

<a href="https://trendshift.io/repositories/12424" target="_blank"></a>

</div>

科学 PDF 文書の翻訳およびバイリンガル比較ツール

フィードバックは GitHub IssuesTelegram グループ

<h2 id="updates">最近の更新</h2>
  • [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)
<h2 id="preview">プレビュー</h2> <div align="center"> </div> <h2 id="demo">公共サービス 🌟</h2>

無料サービス (https://pdf2zh.com/)

インストールなしで 公共サービス をオンラインで試すことができます。

デモ

インストールなしで HuggingFace上のデモ, ModelScope上のデモ を試すことができます。 デモの計算リソースは限られているため、乱用しないようにしてください。

<h2 id="install">インストールと使用方法</h2>

このプロジェクトを使用するための4つの方法を提供しています:コマンドラインポータブルGUI、および Docker

pdf2zhの実行には追加モデル(wybxc/DocLayout-YOLO-DocStructBench-onnx)が必要です。このモデルはModelScopeでも見つけることができます。起動時にこのモデルのダウンロードに問題がある場合は、以下の環境変数を使用してください:

shell
set HF_ENDPOINT=https://hf-mirror.com

For PowerShell user:

shell
$env:HF_ENDPOINT = https://hf-mirror.com
<h3 id="cmd">方法1. コマンドライン</h3>
  1. Pythonがインストールされていること (バージョン3.10 <= バージョン <= 3.12)

  2. パッケージをインストールします:

    bash
    pip install pdf2zh
    
  3. 翻訳を実行し、現在の作業ディレクトリ にファイルを生成します:

    bash
    pdf2zh document.pdf
    
<h3 id="portable">方法2. ポータブル</h3>

Python環境を事前にインストールする必要はありません

setup.bat をダウンロードしてダブルクリックして実行します

<h3 id="gui">方法3. GUI</h3>
  1. Pythonがインストールされていること (バージョン3.10 <= バージョン <= 3.12)

  2. パッケージをインストールします:

    bash
    pip install pdf2zh
    
  3. ブラウザで使用を開始します:

    bash
    pdf2zh -i
    
  4. ブラウザが自動的に起動しない場合は、次のURLを開きます:

    bash
    http://localhost:7860/
    

詳細については、GUIのドキュメント を参照してください。

<h3 id="docker">方法4. Docker</h3>
  1. プルして実行します:

    bash
    docker pull byaidu/pdf2zh
    docker run -d -p 7860:7860 byaidu/pdf2zh
    
  2. ブラウザで開きます:

    http://localhost:7860/
    

クラウドサービスでのDockerデプロイメント用:

<div> <a href="https://www.heroku.com/deploy?template=https://github.com/Byaidu/PDFMathTranslate"> </a> <a href="https://render.com/deploy"> </a> <a href="https://zeabur.com/templates/5FQIGX?referralCode=reycn"> </a> <a href="https://app.koyeb.com/deploy?type=git&builder=buildpack&repository=github.com/Byaidu/PDFMathTranslate&branch=main&name=pdf-math-translate"> </a> </div> <h2 id="usage">高度なオプション</h2>

コマンドラインで翻訳コマンドを実行し、現在の作業ディレクトリに翻訳されたドキュメント example-mono.pdf とバイリンガルドキュメント example-dual.pdf を生成します。デフォルトではGoogle翻訳サービスを使用します。More support translation services can find HERE.

以下の表に、参考のためにすべての高度なオプションをリストしました:

オプション機能
filesローカルファイルpdf2zh ~/local.pdf
linksオンラインファイルpdf2zh http://arxiv.org/paper.pdf
-iGUIに入る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
--authorized[ウェブ認証とカスタム認証ページの追加]pdf2zh -i --authorized users.txt [auth.html]
--prompt[カスタムビッグモデルのプロンプトを使用する]pdf2zh --prompt [prompt.txt]
--onnx[カスタムDocLayout-YOLO ONNXモデルの使用]pdf2zh --onnx [onnx/model/path]
--serverport[カスタムWebUIポートを使用する]pdf2zh --serverport 7860
--dir[batch translate]pdf2zh --dir /path/to/translate/
--configconfiguration filepdf2zh --config /path/to/config/config.json
--serverport[custom gradio server port]pdf2zh --serverport 7860
<h3 id="partial">全文または部分的なドキュメント翻訳</h3>
  • 全文翻訳
bash
pdf2zh example.pdf
  • 部分翻訳
bash
pdf2zh example.pdf -p 1-3,5
<h3 id="language">ソース言語とターゲット言語を指定</h3>

Google Languages CodesDeepL Languages Codes を参照してください

bash
pdf2zh example.pdf -li en -lo ja
<h3 id="services">異なるサービスで翻訳</h3>

以下の表は、各翻訳サービスに必要な 環境変数 を示しています。各サービスを使用する前に、これらの変数を設定してください。

TranslatorServiceEnvironment VariablesDefault ValuesNotes
Google (Default)googleNoneN/ANone
BingbingNoneN/ANone
DeepLdeeplDEEPL_AUTH_KEY[Your Key]See DeepL
DeepLXdeeplxDEEPLX_ENDPOINThttps://api.deepl.com/translateSee DeepLX
OllamaollamaOLLAMA_HOST, OLLAMA_MODELhttp://127.0.0.1:11434, gemma2See Ollama
OpenAIopenaiOPENAI_BASE_URL, OPENAI_API_KEY, OPENAI_MODELhttps://api.openai.com/v1, [Your Key], gpt-4o-miniSee OpenAI
AzureOpenAIazure-openaiAZURE_OPENAI_BASE_URL, AZURE_OPENAI_API_KEY, AZURE_OPENAI_MODEL[Your Endpoint], [Your Key], gpt-4o-miniSee Azure OpenAI
ZhipuzhipuZHIPU_API_KEY, ZHIPU_MODEL[Your Key], glm-4-flashSee Zhipu
ModelScopemodelscopeMODELSCOPE_API_KEY, MODELSCOPE_MODEL[Your Key], Qwen/Qwen2.5-Coder-32B-InstructSee ModelScope
SiliconsiliconSILICON_API_KEY, SILICON_MODEL[Your Key], Qwen/Qwen2.5-7B-InstructSee SiliconCloud
GeminigeminiGEMINI_API_KEY, GEMINI_MODEL[Your Key], gemini-1.5-flashSee Gemini
AzureazureAZURE_ENDPOINT, AZURE_API_KEYhttps://api.translator.azure.cn, [Your Key]See Azure
TencenttencentTENCENTCLOUD_SECRET_ID, TENCENTCLOUD_SECRET_KEY[Your ID], [Your Key]See Tencent
DifydifyDIFY_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.
AnythingLLManythingllmAnythingLLM_URL, AnythingLLM_APIKEY[Your AnythingLLM URL], [Your Key]See anything-llm
Argos TranslateargosSee argos-translate
GrokgrokGORK_API_KEY, GORK_MODEL[Your GORK_API_KEY], grok-2-1212See Grok
DeepSeekdeepseekDEEPSEEK_API_KEY, DEEPSEEK_MODEL[Your DEEPSEEK_API_KEY], deepseek-chatSee DeepSeek
OpenAI-LikedopenailikedOPENAILIKED_BASE_URL, OPENAILIKED_API_KEY, OPENAILIKED_MODELurl, [Your Key], model nameNone

(need Japenese translation) For large language models that are compatible with the OpenAI API but not listed in the table above, you can set environment variables using the same method outlined for OpenAI in the table.

-s service または -s service:model を使用してサービスを指定します:

bash
pdf2zh example.pdf -s openai:gpt-4o-mini

または環境変数でモデルを指定します:

bash
set OPENAI_MODEL=gpt-4o-mini
pdf2zh example.pdf -s openai

For PowerShell user:

shell
$env:OPENAI_MODEL = gpt-4o-mini
pdf2zh example.pdf -s openai
<h3 id="exceptions">例外を指定して翻訳</h3>

正規表現を使用して保持する必要がある数式フォントと文字を指定します:

bash
pdf2zh example.pdf -f "(CM[^RT].*|MS.*|.*Ital)" -c "(\(|\||\)|\+|=|\d|[\u0080-\ufaff])"

デフォルトで LatexMonoCodeItalicSymbol および Math フォントを保持します:

bash
pdf2zh example.pdf -f "(CM[^R]|MS.M|XY|MT|BL|RM|EU|LA|RS|LINE|LCIRCLE|TeX-|rsfs|txsy|wasy|stmary|.*Mono|.*Code|.*Ital|.*Sym|.*Math)"
<h3 id="threads">スレッド数を指定</h3>

-t を使用して翻訳に使用するスレッド数を指定します:

bash
pdf2zh example.pdf -t 1
<h3 id="prompt">カスタム プロンプト</h3>

--promptを使用して、LLMで使用するプロンプトを指定します:

bash
pdf2zh example.pdf -pr prompt.txt

prompt.txtの例:

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つの変数が使用できます。

変数内容
lang_inソース言語
lang_outターゲット言語
text翻訳するテキスト
<h2 id="todo">API</h2>

Python

python
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)

HTTP

bash
pip install pdf2zh[backend]
pdf2zh --flask
pdf2zh --celery worker
bash
curl http://localhost:11008/v1/translate -F "[email protected]" -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
<h2 id="acknowledgement">謝辞</h2> <h2 id="contrib">貢献者</h2> <a href="https://github.com/Byaidu/PDFMathTranslate/graphs/contributors"> </a>

<h2 id="star_hist">スター履歴</h2> <a href="https://star-history.com/#Byaidu/PDFMathTranslate&Date"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=Byaidu/PDFMathTranslate&type=Date&theme=dark" /> <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=Byaidu/PDFMathTranslate&type=Date" /> </picture> </a>