Skip to main content

CLI tool to recognize receipt images using Gemini API and output in XML format

Project description

Harina v3 CLI

Harina v3 CLI

PyPI version Python 3.8+ AI Models MIT License CLI Tool

レシート画像を認識してXML形式で出力するCLIツールです。LiteLLM経由で複数のAIプロバイダー(Google Gemini、OpenAI、Anthropic Claude等)を使用してレシートの内容を解析します。

✨ 機能

  • レシート画像からテキスト情報を抽出
  • 店舗情報、商品情報、金額情報を構造化されたXMLまたはCSV形式で出力
  • Google Gemini APIを使用した高精度な画像認識
  • コマンドライン インターフェース

🚀 クイックスタート

# PyPIからインストール
pip install harina-v3-cli

# 使用方法
harina path/to/receipt.jpg

📦 インストール

PyPIからインストール(推奨)

pip install harina-v3-cli

開発者向けインストール

# リポジトリをクローン
git clone https://github.com/Sunwood-ai-labs/harina-v3-cli.git
cd harina-v3-cli

# 依存関係をインストール
uv sync

# 開発モードでインストール
uv pip install -e .

💡 使用方法

🔑 環境変数の設定

APIキーを設定するには、.envファイルを使用します:

# .envファイルの例をコピー
cp .env.example .env

.envファイルを編集してAPIキーを設定:

# Google Geminiを使用する場合(デフォルト)
GEMINI_API_KEY=your_actual_gemini_api_key_here

# その他のプロバイダーについては.env.exampleを参照

詳細な環境変数設定については、開発者向けガイドをご覧ください。

🛠️ 基本的な使用方法

# 標準出力にXMLを出力(デフォルト: Gemini 1.5 Flash)
harina path/to/receipt_image.jpg

# ファイルに出力(XML形式)
harina path/to/receipt_image.jpg -o output.xml

# CSV形式で出力
harina path/to/receipt_image.jpg --format csv -o output.csv

# 異なるGeminiモデルを使用
harina path/to/receipt_image.jpg --model gemini/gemini-1.5-pro

# OpenAIのGPT-4oを使用する場合(OPENAI_API_KEYが必要)
harina path/to/receipt_image.jpg --model gpt-4o

# Claude 3 Sonnetを使用する場合(ANTHROPIC_API_KEYが必要)
harina path/to/receipt_image.jpg --model claude-3-sonnet-20240229

# 環境変数でデフォルトモデルを設定
export HARINA_MODEL=gpt-4o
harina path/to/receipt_image.jpg

📄 出力形式

XML形式

XMLの出力形式は以下のようになります:

<?xml version="1.0" ?>
<receipt>
  <store_info>
    <name>店舗名</name>
    <address>住所</address>
    <phone>電話番号</phone>
  </store_info>
  <transaction_info>
    <date>2024-01-15</date>
    <time>14:30</time>
    <receipt_number>12345</receipt_number>
  </transaction_info>
  <items>
    <item>
      <name>商品名1</name>
      <quantity>1</quantity>
      <unit_price>100</unit_price>
      <total_price>100</total_price>
    </item>
    <item>
      <name>商品名2</name>
      <quantity>2</quantity>
      <unit_price>200</unit_price>
      <total_price>400</total_price>
    </item>
  </items>
  <totals>
    <subtotal>500</subtotal>
    <tax>50</tax>
    <total>550</total>
  </totals>
  <payment_info>
    <method>現金</method>
    <amount_paid>1000</amount_paid>
    <change>450</change>
  </payment_info>
</receipt>

CSV形式

CSVの出力形式は以下のようになります:

store_name,store_address,store_phone,transaction_date,transaction_time,receipt_number,item_name,item_category,item_subcategory,item_quantity,item_unit_price,item_total_price,subtotal,tax,total,payment_method,amount_paid,change
店舗名,住所,電話番号,2024-01-15,14:30,12345,商品名1,カテゴリ1,サブカテゴリ1,1,100,100,500,50,550,現金,1000,450
店舗名,住所,電話番号,2024-01-15,14:30,12345,商品名2,カテゴリ2,サブカテゴリ2,2,200,400,500,50,550,現金,1000,450

各商品は1行として出力され、店舗情報や取引情報は各商品行に繰り返し含まれます。

🖼️ 対応画像形式

  • JPEG (.jpg, .jpeg)
  • PNG (.png)
  • GIF (.gif)
  • BMP (.bmp)
  • その他PIL(Pillow)でサポートされている形式

📋 必要な依存関係

  • Python 3.8以上
  • litellm
  • click
  • pillow
  • requests

🔐 API キーの取得

使用するモデルプロバイダーに応じて、以下からAPIキーを取得してください:

プロバイダー 取得先 環境変数
Google Gemini Google AI Studio GEMINI_API_KEY
OpenAI GPT OpenAI Platform OPENAI_API_KEY
Anthropic Claude Anthropic Console ANTHROPIC_API_KEY

🔒 セキュリティに関する重要な注意事項

  • APIキーを直接コードに書き込まないでください
  • APIキーをGitリポジトリにコミットしないでください
  • .envファイルは.gitignoreに含まれているため、Gitで追跡されません
  • 本番環境では環境変数を使用してAPIキーを設定してください
  • APIキーが漏洩した場合は、すぐにGoogle AI Studioで無効化し、新しいキーを生成してください

📚 詳細ドキュメント

📄 ライセンス

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

harina_v3_cli-3.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

harina_v3_cli-3.1.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file harina_v3_cli-3.1.0.tar.gz.

File metadata

  • Download URL: harina_v3_cli-3.1.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for harina_v3_cli-3.1.0.tar.gz
Algorithm Hash digest
SHA256 d385bcdb4047e95246c1e64e87555dd7719e4a655d92a853976ddf51b577e818
MD5 8cb088bc859a0c6244e55c659bfd8217
BLAKE2b-256 6c064bfd0e2d83039d6f1948a0ebfdc090aebd8a11ff6c1dfc89aa66ab4f06df

See more details on using hashes here.

Provenance

The following attestation bundles were made for harina_v3_cli-3.1.0.tar.gz:

Publisher: deploy.yml on Sunwood-ai-labs/harina-v3-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 harina_v3_cli-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: harina_v3_cli-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for harina_v3_cli-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed3842dbae7b5957d07befd8e53fcef6e801b976f5e1cf8b8ca9fca29ba39c02
MD5 f7fdfa7eaf16ca2c3e474400940bb47e
BLAKE2b-256 3045a67e4791e3bb38fdfb6d53ffdb0531049222229e0834ee65b4553576b267

See more details on using hashes here.

Provenance

The following attestation bundles were made for harina_v3_cli-3.1.0-py3-none-any.whl:

Publisher: deploy.yml on Sunwood-ai-labs/harina-v3-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