Skip to content

Commit a454601

Browse files
authored
Merge branch 'main' into feature/ai-ocr-vision
2 parents 67b33a3 + 4be491e commit a454601

23 files changed

Lines changed: 3132 additions & 921 deletions

CHANGELOG.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Receipt Scanner Changelog
2+
3+
## Version 2.1.0 - Database Integration & Image Storage
4+
5+
### 🚀 Major Features Added
6+
7+
#### ✅ Persistent Database Storage
8+
- **SQLAlchemy Integration**: Replaced in-memory storage with SQLite database
9+
- **Data Persistence**: All receipt data now persists between server restarts
10+
- **Database Schema**: Enhanced schema with additional metadata fields
11+
- **Automatic Migrations**: Database tables created automatically on startup
12+
13+
#### ✅ Image Storage System
14+
- **Image Persistence**: Original receipt images are now stored on disk
15+
- **Image Retrieval**: New API endpoint to serve stored receipt images
16+
- **Image Display**: Frontend now shows receipt images in review and list views
17+
- **Thumbnail Generation**: List view displays small thumbnails for each receipt
18+
19+
#### ✅ Enhanced Data Model
20+
- **Extended Fields**: Added processing metadata, confidence scores, OCR text
21+
- **Soft Delete**: Receipts are soft-deleted (marked as deleted but preserved)
22+
- **Timestamps**: Automatic created_at and updated_at tracking
23+
- **Image Metadata**: Store image paths and URLs for each receipt
24+
25+
### 🔧 API Improvements
26+
27+
#### New Endpoints
28+
- `GET /api/receipts/{id}/image` - Retrieve original receipt image
29+
- Enhanced all existing endpoints to use database storage
30+
31+
#### Database Schema
32+
```sql
33+
receipts:
34+
- id (Primary Key)
35+
- store_name, purchase_date, total_amount
36+
- category, items (JSON), payment_method, tax_amount
37+
- processing_mode, confidence_score, ocr_text
38+
- image_path, image_url
39+
- user_id (for future authentication)
40+
- created_at, updated_at, uploaded_at
41+
- is_deleted (soft delete flag)
42+
```
43+
44+
### 🎨 Frontend Enhancements
45+
46+
#### Receipt Review View
47+
- **Image Display**: Shows original receipt image alongside extracted data
48+
- **Error Handling**: Graceful fallback when images cannot be loaded
49+
- **Responsive Design**: Images scale appropriately on different screen sizes
50+
51+
#### Receipt List View
52+
- **Thumbnails**: 48x48px thumbnails for each receipt in the list
53+
- **Fallback UI**: Shows placeholder when thumbnail fails to load
54+
- **Improved Layout**: Better visual hierarchy with image, text, and actions
55+
56+
### 📁 File Structure Changes
57+
58+
#### Backend
59+
```
60+
app/
61+
├── database.py # Database configuration
62+
├── db_models.py # SQLAlchemy models
63+
├── main.py # Updated with database integration
64+
└── ...
65+
receipts_images/ # Directory for stored images
66+
test_db.py # Database testing script
67+
init_db.py # Database initialization
68+
```
69+
70+
#### Frontend
71+
```
72+
src/
73+
├── api/index.ts # Added getReceiptImageUrl function
74+
├── types/index.ts # Updated ReceiptData interface
75+
├── App.tsx # Added image display components
76+
└── ...
77+
```
78+
79+
### 🛠️ Development Tools
80+
81+
#### Database Testing
82+
- **test_db.py**: Comprehensive database testing script
83+
- **init_db.py**: Manual database initialization utility
84+
- **Health Checks**: Verify database connectivity and operations
85+
86+
#### Dependencies Added
87+
- **Backend**: sqlalchemy>=2.0.23, alembic>=1.13.0
88+
- **Frontend**: No new dependencies (uses existing functionality)
89+
90+
### 📋 Breaking Changes
91+
92+
⚠️ **Database Migration Required**
93+
- First-time setup will automatically create database tables
94+
- Existing in-memory data will be lost (data was not persistent before)
95+
- New receipt uploads will be stored in the database and file system
96+
97+
⚠️ **API Response Format**
98+
- Receipt objects now include additional fields:
99+
- `processing_mode`, `confidence_score`, `image_path`
100+
- `created_at`, `updated_at` timestamps
101+
- `items` (JSON array), `payment_method`
102+
103+
### 🔮 Future Enhancements Ready
104+
105+
#### Authentication Framework
106+
- Database schema includes `user_id` field
107+
- Ready for JWT authentication implementation
108+
109+
#### Advanced Analytics
110+
- Rich database schema supports complex queries
111+
- Ready for time-based analytics and reporting
112+
113+
#### Cloud Storage
114+
- Image storage abstraction ready for cloud providers
115+
- `image_url` field prepared for cloud storage URLs
116+
117+
### 📖 Usage
118+
119+
#### Running with Database
120+
```bash
121+
# Backend
122+
cd receipt-scanner-app/receipt-scanner-backend
123+
python init_db.py # Optional: initialize database manually
124+
uvicorn app.main:app --reload
125+
126+
# Frontend (no changes to startup)
127+
cd receipt-scanner-app/receipt-scanner-frontend
128+
npm run dev
129+
```
130+
131+
#### Testing Database
132+
```bash
133+
cd receipt-scanner-app/receipt-scanner-backend
134+
python test_db.py
135+
```
136+
137+
### 🐛 Fixes and Improvements
138+
139+
-**Data Persistence**: Receipts no longer lost on server restart
140+
-**Image Recovery**: Can view original receipt images after upload
141+
-**Better Error Handling**: Graceful fallbacks for missing images
142+
-**Performance**: Database queries optimized with proper indexing
143+
-**Scalability**: Ready for production deployment with proper database
144+
145+
### 🔄 Migration Notes
146+
147+
For users upgrading from previous versions:
148+
1. All previous receipt data will be lost (was in-memory only)
149+
2. New uploads will be properly stored and persistent
150+
3. Frontend interface enhanced but maintains same workflow
151+
4. All existing functionality preserved and enhanced
152+
153+
---
154+
155+
**Next Release Preview**: Authentication system, advanced analytics, and cloud storage integration.

README.md

Lines changed: 54 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44

55
AIとOCRを活用した日本語レシート処理システムです。APIキーの安全な管理とセキュリティを最優先に設計されています。
66

7-
## 🆕 新機能
8-
9-
### ✨ 最新アップデート (2025.06.05)
7+
## 🆕 新機能 (v2.0.0)
8+
9+
### ✨ AI-OCR ハイブリッド処理 (2025.06.07)
10+
- **🤖 AI-OCR統合処理**: OpenAIとTesseract OCRを組み合わせた高精度な処理
11+
- **🔄 処理モード選択**: AI、OCR、ハイブリッドモードを選択可能
12+
- **📊 詳細分析機能**: 複数の処理方法で結果を比較・分析
13+
- **🎯 信頼度スコア**: 抽出結果の信頼度を数値化
14+
- **🏷️ 自動カテゴリー分類**: 店名から費目カテゴリーを自動推定
15+
- **📝 商品明細抽出**: レシートから個別商品情報を抽出
16+
- **💳 支払い方法認識**: 現金、クレジット、電子マネーなどを識別
17+
18+
### ✨ 既存機能 (2025.06.05)
1019
- **🔍 OCR処理の大幅改善**: 画像前処理(ノイズ除去、コントラスト調整、二値化)を追加
1120
- **📝 レシート編集機能**: アップロード済みレシートの情報を後から編集可能
1221
- **🗑️ レシート削除機能**: 間違えてアップロードしたレシートを削除可能
@@ -67,6 +76,7 @@ OPENAI_API_KEY=sk-your-actual-openai-api-key
6776
DATABASE_URL=postgresql://user:pass@host:5432/dbname
6877
SECRET_KEY=your-jwt-secret-key
6978
VITE_API_URL=https://your-api-domain.com
79+
OPENAI_MODEL=gpt-4-turbo-preview # 使用するAIモデル
7080
```
7181

7282
### 3. ローカル開発環境
@@ -108,127 +118,58 @@ npm run dev
108118

109119
## 📱 主な機能
110120

121+
### AI-OCR ハイブリッド処理
122+
- **処理モード選択**: アップロード時に処理モードを選択可能
123+
- `ai`: OpenAI APIのみを使用(高精度だが要APIキー)
124+
- `ocr`: Tesseract OCRのみを使用(無料だが精度は中程度)
125+
- `auto`: AI-OCRハイブリッド(推奨 - 両方の良いところを活用)
126+
- **信頼度表示**: 抽出結果の信頼度をパーセンテージで表示
127+
- **詳細分析**: 複数の処理方法で結果を比較可能
128+
111129
### レシートアップロード
112130
- 画像から自動的に店名、日付、金額を抽出
113131
- 日付が読み取れない場合は自動的に現在の日付を設定
114132
- AI(OpenAI)またはOCR(Tesseract)で処理
115133
- 画像前処理により認識精度を向上
134+
- 商品明細の抽出(AI使用時)
135+
- 支払い方法の認識(AI使用時)
116136

117137
### レシート管理
118138
- **編集**: レシート一覧から編集ボタン(✏️)をクリック
119139
- **削除**: レシート一覧から削除ボタン(🗑️)をクリック
120-
- **CSV出力**: 全レシートデータをCSV形式でエクスポート
140+
- **CSV出力**: 全レシートデータをCSV形式でエクスポート(拡張版)
141+
- **ページネーション**: 大量のレシートを効率的に管理
121142

122143
### データ分析
123144
- 費目別の支出をグラフで可視化
124145
- カテゴリー別の経費集計
146+
- 処理方法別の統計情報
147+
- 信頼度スコアの統計
125148

126-
## 🔍 OCRトラブルシューティング
127-
128-
### OCRが動作しない場合
129-
130-
#### 1. Tesseractの確認
131-
```bash
132-
# インストール確認
133-
tesseract --version
134-
135-
# 言語データ確認
136-
tesseract --list-langs
137-
138-
# 日本語データが表示されない場合
139-
sudo apt-get install tesseract-ocr-jpn # Ubuntu/Debian
140-
brew install tesseract-lang # macOS
141-
```
142-
143-
#### 2. OCRテストスクリプトの実行
144-
```bash
145-
cd receipt-scanner-app/receipt-scanner-backend
146-
python test_ocr.py test_receipt.jpg
147-
```
148-
149-
#### 3. よくあるエラーと対処法
150-
151-
**TesseractNotFoundError**
152-
```bash
153-
# Tesseractがインストールされていません
154-
# 上記のインストール手順を実行してください
155-
```
156-
157-
**言語データエラー**
158-
```
159-
Failed loading language 'jpn'
160-
```
161-
解決策: 日本語データをインストール
162-
```bash
163-
sudo apt-get install tesseract-ocr-jpn
164-
```
165-
166-
**画像品質の問題**
167-
- 画像が暗い、ぼやけている → より明るく鮮明な画像を使用
168-
- 傾いている → アプリが自動補正しますが、できるだけ正面から撮影
169-
- 小さすぎる → 最低でも1000x1000ピクセル以上推奨
170-
171-
#### 4. ログの確認
172-
```bash
173-
# バックエンドのログを確認
174-
poetry run uvicorn app.main:app --reload --port 8000 --log-level debug
175-
```
176-
177-
デバッグログで以下を確認:
178-
- `Tesseract found at: [パス]`
179-
- `Available Tesseract languages: ['eng', 'jpn', ...]`
180-
- `OCR extracted text length: [文字数]`
181-
182-
## 🌐 デプロイメント
183-
184-
### Netlify (フロントエンド推奨)
185-
186-
#### 方法1: 自動デプロイ(推奨)
187-
188-
1. **Netlifyダッシュボードにアクセス**
189-
2. **"New site from Git"をクリック**
190-
3. **GitHubリポジトリを選択**
191-
4. **ビルド設定は自動検出** (netlify.tomlで設定済み)
192-
5. **環境変数を設定**:
193-
```
194-
VITE_API_URL = https://your-backend-api-url.com
195-
```
196-
6. **Deploy siteをクリック**
197-
198-
### Railway (バックエンド推奨)
199-
200-
```bash
201-
npm install -g @railway/cli
202-
railway login
203-
railway init
204-
railway variables set OPENAI_API_KEY=sk-your-key
205-
railway variables set ENVIRONMENT=production
206-
railway up
207-
```
208-
209-
### Docker での実行
210-
211-
```bash
212-
# バックエンドのみ
213-
cd receipt-scanner-app/receipt-scanner-backend
214-
docker build -t receipt-scanner-backend .
215-
docker run -p 8000:8000 \
216-
-e OPENAI_API_KEY="your-api-key" \
217-
receipt-scanner-backend
218-
```
219-
220-
## 📊 API エンドポイント
149+
## 🔍 API エンドポイント (v2.0.0)
221150

222151
| エンドポイント | メソッド | 説明 | レート制限 |
223152
|----------------|----------|------|------------|
153+
| `/` | GET | ルートエンドポイント(処理能力情報を含む) | なし |
224154
| `/healthz` | GET | ヘルスチェック | なし |
225-
| `/api/status` | GET | システム状態 | なし |
226-
| `/api/receipts/upload` | POST | レシートアップロード ||
227-
| `/api/receipts` | GET | レシート一覧 | なし |
155+
| `/api/status` | GET | 詳細なシステム状態 | なし |
156+
| `/api/capabilities` | GET | 処理能力の詳細情報 | なし |
157+
| `/api/receipts/upload` | POST | レシートアップロード(モード選択可) ||
158+
| `/api/receipts/analyze` | POST | レシート分析(保存なし) ||
159+
| `/api/receipts` | GET | レシート一覧(ページネーション対応) | なし |
160+
| `/api/receipts/{id}` | GET | 特定のレシート取得 | なし |
228161
| `/api/receipts/{id}` | PUT | レシート更新 | なし |
229162
| `/api/receipts/{id}` | DELETE | レシート削除 | なし |
230-
| `/api/receipts/export` | GET | CSV エクスポート | なし |
231-
| `/api/stats` | GET | 統計情報 | なし |
163+
| `/api/receipts/export/csv` | GET | CSV エクスポート(拡張版) | なし |
164+
| `/api/stats` | GET | 拡張統計情報 | なし |
165+
166+
### アップロードパラメータ
167+
`/api/receipts/upload` エンドポイントで使用可能:
168+
- `file`: アップロードする画像ファイル(必須)
169+
- `processing_mode`: 処理モード(オプション)
170+
- `"ai"`: AIのみ使用
171+
- `"ocr"`: OCRのみ使用
172+
- `"auto"` または省略: AI-OCRハイブリッド
232173

233174
**API ドキュメント**: `http://localhost:8000/docs`
234175

@@ -239,7 +180,8 @@ docker run -p 8000:8000 \
239180
**バックエンド:**
240181
| 変数名 | 必須 | デフォルト | 説明 |
241182
|--------|------|------------|------|
242-
| `OPENAI_API_KEY` || - | OpenAI APIキー |
183+
| `OPENAI_API_KEY` || - | OpenAI APIキー(AI処理に必要) |
184+
| `OPENAI_MODEL` || `gpt-4-turbo-preview` | 使用するAIモデル |
243185
| `ENVIRONMENT` || `development` | 実行環境 |
244186
| `DEBUG` || `true` | デバッグモード |
245187
| `RATE_LIMIT_REQUESTS` || `10` | レート制限リクエスト数 |
@@ -310,3 +252,10 @@ MIT License - see [LICENSE](LICENSE) file for details.
310252
**🔒 重要**: このアプリケーションはAPIキーなどの機密情報を安全に管理するために設計されています。セキュリティガイドラインに従って使用してください。
311253

312254
**💡 サポート**: 問題が発生した場合は [Issues](https://github.com/crackerky/receipt-scanner/issues) を確認するか、新しいIssueを作成してください。
255+
256+
**🎯 v2.0.0の主な改善点**:
257+
- AI-OCRハイブリッド処理による精度向上
258+
- 処理モード選択による柔軟性の向上
259+
- 詳細な分析機能の追加
260+
- 信頼度スコアによる品質管理
261+
- 拡張されたCSVエクスポート機能

0 commit comments

Comments
 (0)