Skip to content

deb-sig/ai-bill-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

账单转 Beancount 工具

一个智能财务管理工具,能够将账单文件自动转换为 Beancount 格式的记账记录。

🎯 功能特点

  • 📤 上传账单:支持 CSV 和 TXT 格式的账单文件
  • 🤖 AI 智能处理:使用 DeepSeek 大模型自动解析账单
  • 💾 自动保存:生成的 Beancount 文件自动保存到本地
  • 👀 预览查看:在浏览器中预览生成的结果
  • 📥 快速下载:一键下载生成的 Beancount 文件
  • 📊 文件管理:查看所有已生成的文件列表

⚙️ 安装步骤

1. 安装依赖

pip install -r requirements.txt

2. 配置 API 密钥

首次运行时会提示输入 DeepSeek API 密钥:

python app.py

或者直接设置环境变量:

export DEEPSEEK_API_KEY="your-api-key-here"

3. 启动应用

python app.py

应用将在 http://localhost:5000 启动

📋 账单格式

CSV 格式示例

2026-02-09,交通出行,铁路12306,支出宝,火车票,支出,484.00,余额宝,交易成功,2026020922001403611445337252
2026-02-10,餐饮,星巴克,支出宝,咖啡,支出,45.00,余额宝,交易成功,2026021022001403611445337253

TXT 格式

一行一条记录,采用相同的格式。

🚀 使用流程

  1. 打开应用:在浏览器中访问 http://localhost:5000

  2. 选择账单文件

    • 点击上传区域或拖放文件到上传框
    • 支持 CSV 和 TXT 格式
  3. 等待处理

    • AI 会自动处理每条交易记录
    • 将账单转换为 Beancount 格式
  4. 查看结果

    • 预览生成的 Beancount 内容
    • 检查转换是否正确
  5. 下载文件

    • 点击"下载 Beancount 文件"保存到本地
    • 或从文件列表中下载之前生成的文件

📁 项目结构

/Users/gaoce/code/aifin/
├── app.py                  # Flask 后端应用
├── beancount.py           # Beancount 转换脚本
├── requirements.txt       # Python 依赖
├── templates/
│   └── index.html         # 前端 HTML 模板
├── static/
│   ├── style.css         # 样式表
│   └── script.js         # 前端 JavaScript
└── output/               # 生成的 Beancount 文件输出目录

🔧 API 端点

POST /api/upload

上传账单文件进行处理

请求

  • file: 账单文件(CSV 或 TXT)

响应

{
    "success": true,
    "filename": "beancount_20260214_120000.beancount",
    "transactions_count": 5,
    "content": "...Beancount 内容..."
}

GET /api/download/

下载生成的 Beancount 文件

GET /api/files

获取已生成的文件列表

响应

{
    "success": true,
    "files": [
        {
            "filename": "beancount_20260214_120000.beancount",
            "size": 2048,
            "modified": "2026-02-14T12:00:00"
        }
    ]
}

🎯 生成的 Beancount 示例

;; -*- mode: beancount -*-
plugin "beancount.plugins.auto_accounts"

1900-01-01 open Assets:Alipay
1900-01-01 open Assets:BankAccount
1900-01-01 open Expenses:Transport
1900-01-01 open Expenses:Dining
1900-01-01 open Expenses:Shopping
1900-01-01 open Expenses:Other
1900-01-01 open Income:Salary
1900-01-01 open Income:Other

2026-02-09 * "交通出行" "火车票"
  Assets:Alipay      -484.00 CNY
  Expenses:Transport  484.00 CNY

2026-02-10 * "餐饮" "咖啡"
  Assets:Alipay      -45.00 CNY
  Expenses:Dining     45.00 CNY

🐛 故障排除

问题:提示缺少 DEEPSEEK_API_KEY

解决方案

  1. 首次运行会提示输入 API 密钥
  2. 或设置环境变量:export DEEPSEEK_API_KEY="your-key"

问题:处理速度慢

原因

  • AI 模型处理需要时间
  • 账单数量较多

解决方案

  • 耐心等待
  • 可将大文件分批处理

问题:转换结果不理想

解决方案

  1. 检查账单格式是否正确
  2. 手动编辑生成的 Beancount 文件调整
  3. 查看 Beancount 官方文档了解语法

📝 注意事项

  • 生成的 Beancount 文件存储在 output/ 目录
  • 金额默认使用 CNY(人民币)货币单位
  • 账户和科目名称可根据个人需求在生成后修改
  • 建议先备份原始账单文件

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License

About

利用 DeepSeek 模型转换账单

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors