translatedoc
PDFなどのドキュメントを翻訳するツール。
Unstructuredで読み込み、OpenAI APIに渡しているだけ。
インストール
1. Unstructured
インストール例:
sudo apt install poppler-utils poppler-data tesseract-ocr tesseract-ocr-jpn
pip install unstructured[all-docs] --extra-index-url https://download.pytorch.org/whl/cu118
python -m nltk.downloader --exit-on-error punkt_tab averaged_perceptron_tagger_eng
cu118のところは環境に合わせて変更する。
詳細はUnstructuredのドキュメントを参照。
2. translatedoc
pip install translatedoc
使い方
基本
export OPENAI_API_KEY=<your_api_key>
translatedoc --language=Japanese <input_files_and_or_urls>
カレントディレクトリにファイル名.Source.txtとファイル名.Japanese.txtが生成される。
詳細は translatedoc --help を参照。
応用その1
テキストの抽出と翻訳を別々に行うこともできる。
translatedoc-step1 <input_files_and_or_urls>
translatedoc-step2 --language=Japanese <input_text_files>
応用その2
Pythonライブラリとしても使用可能。
import os
import translatedoc
result_text: str = translatedoc.extract_text("path_or_url.pdf")
model = "gpt-3.5-turbo-1106"
openai_client = openai.OpenAI(base_url=os.environ.get("OPENAI_API_BASE"))
chunks: list[str] = translatedoc.partition(result_text, model)
translated = "\n\n".join(
translatedoc.translate(chunk, model, "Japanese", openai_client) for chunk in chunks
)
環境変数
| 環境変数名 | 概要 | デフォルト値 |
|---|---|---|
OPENAI_API_BASE |
OpenAI APIのベースURL | https://api.openai.com/v1 |
OPENAI_API_KEY |
OpenAI APIのキー | - |
TRANSLATEDOC_MODEL |
翻訳に使用するモデル | gpt-4o-mini |
TRANSLATEDOC_STRATEGY |
ドキュメントのパーティション化に使用する戦略 | hi_res |
Metadata
Release files for translatedoc 1.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| translatedoc-1.6.0.tar.gz | 146.7 kB | Without provenance | Details for translatedoc-1.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| translatedoc-1.6.0-py3-none-any.whl | Python 3 | none | any | Details for translatedoc-1.6.0-py3-none-any.whl |
Total release size: 159.2 kB
Release files / translatedoc-1.6.0.tar.gz
| Download URL | translatedoc-1.6.0.tar.gz |
|---|---|
| Size | 146.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2833b69708b886e9f12e7c1297671f2b829cf5efa73cfcf63aa5b13df0fea2bb
|
|
BLAKE2b-256 checksum How to use checksums |
37773729f9cbc247e7cff1e1cca61ffcf999dd46d4f5d191b3ade303bff471d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Release files / translatedoc-1.6.0-py3-none-any.whl
| Download URL | translatedoc-1.6.0-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
856f6ff273d8bf0c3d80bf00b7ef18208947f778c15d3d0909b2d320b2369ccc
|
|
BLAKE2b-256 checksum How to use checksums |
4834645d0803fd9dc2029c00eb86aa880c7a7c51912fa18769f5ab1f2331913b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Security for translatedoc 1.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.