LibreTranslate で自分用翻訳サーバ

ArgosTranslate でローカルで機械翻訳を試していい感じだったので,ArgosTranslate を使った翻訳ウェブサーナのLibreTanslate も試してみました.

pipでかんたんに導入できます.ここではvenvで環境を分けています.

$ python3 -m venv venv (1)
$ source venv/bin/activate (2)
$ pip install libretranslate (3)
$ du -Hs . (4)
3518928 .
$ libretranslate (5)
Updating language models
Found 58 models
Downloading Arabic → English (1.0) ...
Downloading Azerbaijani → English (1.5) ...
Downloading Catalan → English (1.7) ...
  :
^c
$ du -Hs ~/.local/share/argos-translate/ (6)
6137956 /home/matoken/.local/share/argos-translate/
$ libretranslate --frontend-language-source en --frontend-language-target ja (7)
Running on http://127.0.0.1:5000
  1. venv設定
  2. venv反映
  3. pipでLibreTranslateを導入
  4. 容量確認
  5. モデルデータが無い場合はダウンロードされる
  6. モデルデータの容量確認
  7. 翻訳元既定値をen, 翻訳先既定値をjaにして起動
Note

argostranslateも一緒に導入されます.

$ argos-translate -h
usage: argos-translate [-h] [--from-lang FROM_LANG] [--to-lang TO_LANG] [TEXT]

Open-source offline translation.

positional arguments:
  TEXT                  The text to translate. Read from standard input if missing.

options:
  -h, --help            show this help message and exit
  --from-lang FROM_LANG, -f FROM_LANG
                        The code for the language to translate from (ISO 639-1)
  --to-lang TO_LANG, -t TO_LANG
                        The code for the language to translate to (ISO 639-1)

ウェブブラウザで http://127.0.0.1:5000/ 🏛️ にアクセスします.左側のテキストエリアに翻訳したい文字列を入力すると入力されるたびに翻訳され右側にテキストエリアに結果が表示されます.

libretranslate00

curl経由でも実行してみます.

$ curl -X POST --silent --show-error -F "q=hello world." -F "source=en" -F "target=ja" http://127.0.0.1:5000/translate | jq .
{
  "translatedText": "こんにちは世界。."
}
Tip

ウェブインターフェイスで一部の言語しか選べなかったり,

Cannot translate text: 400 Bad Request: English (en) is not available as a target language from Japanese (ja)

のようなエラーとなった.

初回起動時にダウンロードする言語モデルが壊れていたためのようで一旦削除してダウンロードし直すことで動作するようになった.(ダウンロード中にNotePCをサスペンドしてしまったせいだと思う……)

$ rm -r ~/.local/share/argos-translate
$ libretranslate
Updating language models
Found 58 models
Downloading Arabic → English (1.0) ...
Downloading Azerbaijani → English (1.5) ...
  :
環境
$ dpkg-query -W python3 python3-pip
python3 3.10.6-3+b1
python3-pip     22.3.1+dfsg-1
e$ lsb_release -a
Distributor ID: Debian
Description:    Debian GNU/Linux bookworm/sid
Release:        n/a
Codename:       bookworm
$ arch
x86_64

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)