Python Formatters, Linters, and Testers Runner.
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
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-3.5-turbo-1106 |
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.2.0.tar.gz
(9.1 kB
view hashes)
Built Distribution
Close
Hashes for translatedoc-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a786c32923d002a942b4e1ae227af2570d9b14407fb41f9c43e3d199b870407a |
|
MD5 | 512b5a62a9ef5b4d857a558c28a6aafa |
|
BLAKE2b-256 | b696d9f3afbd7b45c2ab550eb103182f881a69d7740bf7a9aab77e25637f2183 |