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

Python 3.8+ AI Models MIT License CLI Tool

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

✨ 機能

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

🚀 クイックスタート

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

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

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

📦 インストール

uvを使用して環境構築とインストールを行います:

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

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

💡 使用方法

🔑 環境変数の設定

Gemini API キーを設定する方法は以下の通りです:

方法1: .envファイルを使用(推奨)

プロジェクトルートに.envファイルを作成してください:

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

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

# Google Geminiを使用する場合
GEMINI_API_KEY=your_actual_gemini_api_key_here

# OpenAI GPTを使用する場合
OPENAI_API_KEY=your_actual_openai_api_key_here

# Anthropic Claudeを使用する場合
ANTHROPIC_API_KEY=your_actual_anthropic_api_key_here

重要: 実際のAPIキーを設定してください。プレースホルダーは実際の値に置き換えてください。

方法2: 環境変数を直接設定

Windows (PowerShell):

# Google Geminiの場合
$env:GEMINI_API_KEY="your_actual_gemini_api_key_here"

# OpenAI GPTの場合
$env:OPENAI_API_KEY="your_actual_openai_api_key_here"

# Anthropic Claudeの場合
$env:ANTHROPIC_API_KEY="your_actual_anthropic_api_key_here"

Windows (CMD):

rem Google Geminiの場合
set GEMINI_API_KEY=your_actual_gemini_api_key_here

rem OpenAI GPTの場合
set OPENAI_API_KEY=your_actual_openai_api_key_here

rem Anthropic Claudeの場合
set ANTHROPIC_API_KEY=your_actual_anthropic_api_key_here

Linux/macOS:

# Google Geminiの場合
export GEMINI_API_KEY="your_actual_gemini_api_key_here"

# OpenAI GPTの場合
export OPENAI_API_KEY="your_actual_openai_api_key_here"

# Anthropic Claudeの場合
export ANTHROPIC_API_KEY="your_actual_anthropic_api_key_here"

🛠️ 基本的な使用方法

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

# ファイルに出力
harina path/to/receipt_image.jpg -o output.xml

# 異なる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 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>

🖼️ 対応画像形式

  • 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.0.0.tar.gz (8.8 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.0.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: harina_v3_cli-3.0.0.tar.gz
  • Upload date:
  • Size: 8.8 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.0.0.tar.gz
Algorithm Hash digest
SHA256 2d70b704fc5201cce897b31fbc4c08c67b5fbaae38a84ff4ba69d23a036403db
MD5 ab8b69193c4975573ee2bf92436856f4
BLAKE2b-256 2a8559b3475a789c0ca4e1617cad71327753632959ed850fd6bfe9d7a301f773

See more details on using hashes here.

Provenance

The following attestation bundles were made for harina_v3_cli-3.0.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.0.0-py3-none-any.whl.

File metadata

  • Download URL: harina_v3_cli-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f61b1436dd843e8b834de3edf0bbb9587613e6dad4b493406b6d10bb2a49a5a
MD5 267ba1ba79704b2c1a74842e8a618790
BLAKE2b-256 53a511d22492822b7a0f22a8c25c99f95de1a0a1fea7a7ff04cee6959e1b10c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for harina_v3_cli-3.0.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