Skip to main content

CAT-Translate-7b GGUF モデルを使った日英・英日翻訳CLIツール(サーバーモード対応)

Project description

English 日本語

cat-translate-cli

CAT-Translate-7b の量子化 GGUF モデルを使った、日英・英日翻訳の CLI ツールです。

Apple Silicon (Metal) に対応しており、Mac でローカル実行できます。

サーバーモードを使うと、モデルを常駐させてブラウザからも CLI からも高速に翻訳できます。

必要なもの

  • macOS(Apple Silicon 推奨)
  • Python 3.10 以上
  • uv(Python パッケージマネージャー)
  • Xcode Command Line Tools(xcode-select --install

インストール

# リポジトリをクローン
git clone https://github.com/yourname/cat-translate-cli.git
cd cat-translate-cli

# Metal(GPU)対応でインストール
CMAKE_ARGS='-DGGML_METAL=on' uv sync

# 仮想環境アクティブ
source .venv/bin/activate

注意: llama-cpp-python は C++ のビルドが必要です。 Apple Silicon で GPU を使うには CMAKE_ARGS='-DGGML_METAL=on' を付けてください。

使い方

CLI(コマンドライン)

# 日本語 → 英語(言語は自動判定)
cat-translate '猫はとてもかわいいです。'

# 英語 → 日本語(言語は自動判定)
cat-translate 'Cats are very cute.'

# 翻訳先の言語を指定(ja / en の短縮形が使えます)
cat-translate 'Hello, world!' --to ja
cat-translate 'こんにちは' --to en

# フルネームでも OK
cat-translate 'Hello, world!' --to Japanese

# 原文の言語も明示的に指定
cat-translate 'Hello!' --from en --to ja

# ファイルから翻訳
cat-translate --file input.txt

# パイプ入力
echo 'こんにちは世界' | cat-translate

# 翻訳結果だけリダイレクト(ログは出ません)
cat-translate '猫はかわいい' > output.txt

サーバーモード(高速翻訳)

サーバーを起動すると、モデルが常駐するため CLI での翻訳が大幅に高速化します。 ブラウザからも Web UI で翻訳できます。

# ターミナル1: サーバーを起動(初回のみモデル読み込みに時間がかかります)
cat-translate-server

# ターミナル2: CLI で翻訳(サーバーが起動中なら自動的にサーバー経由)
cat-translate '猫はとてもかわいいです。'

# ブラウザで Web UI を開く
# → http://127.0.0.1:7860

サーバーが起動していない場合は、従来通りローカルでモデルを読み込んで翻訳します。

# サーバーを使わず、常にローカルで翻訳
cat-translate '猫はかわいい' --no-server

主なオプション(CLI)

オプション 説明 デフォルト
--from LANG 原文の言語(ja / en / Japanese / English) 自動判定
--to LANG 翻訳先の言語(ja / en / Japanese / English) 自動判定
--model GGUF ファイル名 CAT-Translate-7b.i1-Q4_K_M.gguf
--model-path ローカルの GGUF ファイルパス なし(HF からダウンロード)
--repo-id Hugging Face リポジトリ ID mradermacher/CAT-Translate-7b-i1-GGUF
--n-gpu-layers GPU に載せるレイヤー数 -1(全レイヤー)
--n-ctx コンテキストウィンドウサイズ 4096
--max-tokens 最大生成トークン数 2048
--verbose 詳細ログを表示 オフ
--server-url 翻訳サーバーの URL http://127.0.0.1:7860
--no-server サーバーを使わずローカルで翻訳 オフ

主なオプション(サーバー)

オプション 説明 デフォルト
--host サーバーのホスト 127.0.0.1
--port サーバーのポート 7860
--model GGUF ファイル名 CAT-Translate-7b.i1-Q4_K_M.gguf
--model-path ローカルの GGUF ファイルパス なし
--n-gpu-layers GPU に載せるレイヤー数 -1
--n-ctx コンテキストウィンドウサイズ 4096
--max-tokens 最大生成トークン数 2048
--verbose 詳細ログを表示 オフ

別の量子化モデルを使う

# 軽量モデル(Q2_K)を使う場合
cat-translate 'こんにちは' --model CAT-Translate-7b.i1-Q2_K.gguf

# 高品質モデル(Q6_K)を使う場合
cat-translate 'こんにちは' --model CAT-Translate-7b.i1-Q6_K.gguf

CPU のみで実行する場合

cat-translate 'こんにちは' --n-gpu-layers 0

トラブルシューティング

動作がおかしい場合は --verbose を付けて詳細ログを確認してください。

cat-translate '猫はかわいい' --verbose

モデルについて

ライセンス

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cat_translate_cli-0.2.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cat_translate_cli-0.2.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file cat_translate_cli-0.2.0.tar.gz.

File metadata

  • Download URL: cat_translate_cli-0.2.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cat_translate_cli-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bcbfcbf753afbe4fd6021a5e27ea80148e7482079d56a6c4189341b24d2c5e5f
MD5 1614886c46eabaa9cddcb7ad75090a3e
BLAKE2b-256 a296dae891bda1df23b9decfa09e9799cfdf1fd65be051e85359df892b0f8b78

See more details on using hashes here.

Provenance

The following attestation bundles were made for cat_translate_cli-0.2.0.tar.gz:

Publisher: publish.yml on Shuichi346/cat-translate-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cat_translate_cli-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cat_translate_cli-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e31bbc14a9ae2f7842edb8b1cf71153408d1d8525cd2f1ffdbf8689afdd30bc
MD5 b10e35fe80b49637df64082794bf3528
BLAKE2b-256 b29dc1323c3fd23908b6c744716420f7b4d02db476a2219ac4faddcdc2b39e1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cat_translate_cli-0.2.0-py3-none-any.whl:

Publisher: publish.yml on Shuichi346/cat-translate-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page