PDFなどのドキュメントを翻訳するツール。
Project description
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 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
translatedoc-1.6.0.tar.gz
(146.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file translatedoc-1.6.0.tar.gz.
File metadata
- Download URL: translatedoc-1.6.0.tar.gz
- Upload date:
- Size: 146.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2833b69708b886e9f12e7c1297671f2b829cf5efa73cfcf63aa5b13df0fea2bb
|
|
| MD5 |
ab3d5966294fd6cfcf5ef8884a825a12
|
|
| BLAKE2b-256 |
37773729f9cbc247e7cff1e1cca61ffcf999dd46d4f5d191b3ade303bff471d0
|
File details
Details for the file translatedoc-1.6.0-py3-none-any.whl.
File metadata
- Download URL: translatedoc-1.6.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
856f6ff273d8bf0c3d80bf00b7ef18208947f778c15d3d0909b2d320b2369ccc
|
|
| MD5 |
5340572983904ace57fbbfc693f1e4e9
|
|
| BLAKE2b-256 |
4834645d0803fd9dc2029c00eb86aa880c7a7c51912fa18769f5ab1f2331913b
|