hamzasalahuddin72/invoicepie-expense-intelligence

GitHub: hamzasalahuddin72/invoicepie-expense-intelligence

一个基于 Python 和 Streamlit 的发票费用智能分析系统,能从发票 PDF 中提取结构化数据并自动校验、查重和可视化展示。

Stars: 0 | Forks: 0

InvoicePie app icon # InvoicePie — 基于 AI 的发票与费用智能分析 基于 AI 的发票与费用智能分析系统,用于从发票 PDF 中提取结构化数据,验证缺失或可疑字段,检测重复发票,并展示费用洞察。 [![InvoicePie 在线演示](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/927850ad67195353.svg)](https://invoicepie.streamlit.app/) **在线演示:** https://invoicepie.streamlit.app/ InvoicePie 是一个基于 AI 的发票与费用智能分析系统,它能从发票 PDF 中提取结构化数据,验证缺失或可疑字段,检测重复发票,将处理后的记录存储在数据库中,并通过仪表板展示费用洞察。 本项目作为一个实用的作品集项目进行开发,旨在展示应用 AI 工程、文档处理、Python 开发、数据库设计、验证逻辑、重复检测和仪表板报告的能力。 ## 当前状态 InvoicePie 目前支持一个可运行的本地 pipeline: ``` Sample invoice PDF ↓ PDF text extraction ↓ Invoice field parsing ↓ Structured JSON output ↓ Invoice validation report ↓ Duplicate detection report ↓ SQLite database storage ↓ Streamlit expense dashboard ``` 当前的示例数据集包含: ``` 3 invoice records 1 validation report 1 duplicate invoice match ``` 仪表板目前显示: ``` Invoices: 3 Total Spend: £2,760.00 Unpaid Invoices: 3 Validation Issues: 0 Duplicate Matches: 1 ``` ## 已实现的功能 ### PDF 文本提取 InvoicePie 可以使用 PyMuPDF 从基于文本的发票 PDF 中提取可读文本。 当前文件: ``` app/extractor.py ``` ### 结构化发票解析 提取的发票文本会被转换为结构化的 JSON 字段,例如: ``` supplier_name invoice_number invoice_date due_date vat_number subtotal vat_amount total_amount payment_status category currency source_file ``` 当前文件: ``` app/parser.py ``` ### 发票验证 解析后的发票记录会进行缺失或可疑值的检查。 当前的验证检查包括: ``` required fields are present invoice date is valid due date is valid due date is not earlier than invoice date subtotal is valid VAT amount is valid total amount is valid subtotal plus VAT matches total amount payment status uses an expected value ``` 当前文件: ``` app/validator.py ``` ### 重复发票检测 InvoicePie 会比对解析后的发票记录,并使用以下方法标记可能的重复项: ``` supplier name invoice number invoice date due date total amount ``` 当前文件: ``` app/duplicate_detector.py ``` ### SQLite 数据库存储 处理后的发票记录、验证报告和重复匹配项会存储在本地 SQLite 数据库中。 当前文件: ``` app/database.py ``` 数据库表: ``` invoices validation_reports duplicate_matches ``` ### Streamlit 仪表板 本地 Streamlit 仪表板会显示汇总指标、支出洞察、发票记录、验证结果和重复警告。 当前文件: ``` app/dashboard.py ``` ## 技术栈 ``` Python PyMuPDF pandas SQLite Streamlit python-dateutil Git / GitHub ``` 计划后续添加的内容可能包括: ``` OCR support PostgreSQL FastAPI Docker cloud deployment AI-assisted invoice review ``` ## 项目结构 ``` invoicepie-expense-intelligence/ │ ├── app/ │ ├── dashboard.py │ ├── database.py │ ├── duplicate_detector.py │ ├── extractor.py │ ├── main.py │ ├── parser.py │ └── validator.py │ ├── data/ │ ├── database/ │ ├── duplicate_reports/ │ ├── extracted_json/ │ ├── sample_invoices/ │ └── validation_reports/ │ ├── docs/ │ └── screenshots/ │ ├── scripts/ │ └── create_sample_invoice.py │ ├── tests/ ├── PROJECT_LOG.md ├── README.md ├── requirements.txt └── .gitignore ``` ## 如何在本地运行 ### 1. 克隆代码库 ``` git clone https://github.com/hamzasalahuddin72/invoicepie-expense-intelligence.git cd invoicepie-expense-intelligence ``` ### 2. 创建并激活虚拟环境 在 Windows PowerShell 上: ``` python -m venv venv .\venv\Scripts\activate ``` ### 3. 安装依赖项 ``` pip install -r requirements.txt ``` ### 4. 生成示例发票 PDF ``` python scripts/create_sample_invoice.py ``` 这会创建: ``` data/sample_invoices/hotel_invoice_001.pdf ``` ### 5. 从示例发票中提取文本 ``` python app/extractor.py ``` ### 6. 将发票解析为结构化 JSON ``` python app/parser.py ``` 这会创建: ``` data/extracted_json/hotel_invoice_001.json ``` ### 7. 运行发票验证 ``` python app/validator.py ``` 这会创建: ``` data/validation_reports/hotel_invoice_001_validation.json ``` ### 8. 运行重复检测 ``` python app/duplicate_detector.py ``` 这会创建: ``` data/duplicate_reports/duplicate_report.json ``` ### 9. 将处理后的数据导入 SQLite ``` python app/database.py ``` 这会创建本地数据库: ``` data/database/invoicepie.db ``` ### 10. 启动仪表板 ``` python -m streamlit run app/dashboard.py ``` 然后打开: ``` http://localhost:8501 ``` ## 示例输出 当前仪表板显示: ``` Invoices: 3 Total Spend: £2,760.00 Unpaid Invoices: 3 Validation Issues: 0 Duplicate Matches: 1 ``` 重复检测器目前识别出以下两者之间可能存在的一个重复项: ``` hotel_invoice_001.json hotel_invoice_001_duplicate.json ``` ## 当前限制 InvoicePie 目前是一个 MVP,仅适用于小型示例数据集。 当前限制: ``` only text-based PDF invoices are supported scanned invoices are not supported yet the parser depends on predictable invoice labels duplicate detection uses rule-based scoring the SQLite database is local only the dashboard is not deployed online yet there is no file upload interface yet there is no authentication or user management ``` 这些限制在现阶段是有意为之。本项目正按里程碑逐步构建,以便系统的每个部分都能被理解、测试和改进。 ## 计划改进 计划的下一步包括: ``` add more varied sample invoices add bad invoice examples for validation testing improve duplicate detection for near-matches add dashboard filters add file upload from the dashboard add export options add OCR support for scanned invoices add FastAPI backend add Docker support deploy the dashboard online explore AI-assisted invoice review ``` ## 项目日志 项目记录于: ``` PROJECT_LOG.md ``` 日志说明了在每个里程碑构建了什么、为什么每一步都很重要、学到了什么、当前的局限性以及计划的下一步改进。 ## 作品集目的 本项目旨在展示在以下方面的实际能力: ``` Python development document processing structured data extraction data validation database storage duplicate detection dashboard reporting business problem-solving clear project documentation ``` InvoicePie 旨在演示如何将原始发票文档转化为结构化、经过验证且可供审查的业务数据。
标签:AI工程, Kubernetes, Streamlit, 发票处理, 数据校验, 文档提取, 访问控制, 逆向工具