A newer version of the Gradio SDK is available: 6.20.0
title: Cuentas Claras
emoji: ๐งฎ
colorFrom: green
colorTo: indigo
sdk: gradio
sdk_version: 6.15.2
python_version: '3.12'
app_file: app.py
pinned: false
license: apache-2.0
๐งฎ Cuentas Claras โ Your Pocket Accountant Agent
"Cuentas claras, amistades largas." โ Clear accounts make for long friendships. Snap a receipt or paste an invoice. The agent books it, applies the right formulas, tells you what you owe the SAT, and explains why โ in plain language.
A small-model AI accountant agent that keeps the books, applies the math, and follows the rules โ built for the Hugging Face "Small Models, Big Adventures" Hackathon (June 2026).
It is designed for the people who can't afford a full-time accountant: freelancers (personas fรญsicas) and micro / small businesses in Mexico โ with a bonus USA mode for cross-border freelancers and Mexican entrepreneurs selling into the United States.
Chapter Zero โ Why this exists
In Mexico, a freelance designer or a corner papelerรญa lives in fear of two things: the SAT (the tax authority) and a shoebox full of receipts. Accountants are expensive, spreadsheets are intimidating, and the SAT portal is a maze of acronyms โ RFC, CFDI, ISR, IVA, RESICO, DIOT. Most micro-entrepreneurs end up either overpaying, missing deadlines, or guessing.
Cuentas Claras is the accountant they can't afford. It is not a chatbot that talks about taxes โ it is an agent that:
- Stores every income and expense as a proper double-entry ledger.
- Applies real formulas (ISR, IVA, RESICO, ratios, depreciation) through a deterministic engine โ the model never does the arithmetic, so it never hallucinates a number.
- Follows the regulation by grounding its answers in an indexed corpus of Mexican (and US) tax rules โ it cites the rule, it doesn't invent it.
- Explains every result in plain Spanish or English, like a patient accountant would.
All of this runs on a model small enough to fit on a laptop. No giant LLM. No cloud API required.
Track
๐ก Chapter One โ Backyard AI. Built for a specific, real person: (builder fills in) โ a freelance graphic designer / the owner of a small neighborhood business who currently tracks income in a notebook and dreads tax season. They will actually use it during the hack window, and that usage is part of the story.
The honest small-model fit: tax math must be exact, so we deliberately push the hard numbers into a deterministic engine and use the 8B model only for what small models are genuinely good at โ language understanding, classification, and orchestration. The constraint shapes the architecture instead of fighting it.
How it works
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐งพ Receipt photo โโโถ โ ACCOUNTANT AGENT โ
๐ CFDI XML / CSV โโโถ โ (MiniCPM 8B ยท llama.cpp ยท local-first) โ
๐ฌ "How much ISR โ โ
do I owe in May?" โ plans โ calls tools โ grounds โ explains โ
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ (function / tool calls)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ โผ โผ โผ โผ
โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ
โ Ledger โ โ Classifier โ โ Tax Engine โ โ Reg. Retrieverโ โ Reports โ
โ (SQLite, โ โ (fine-tuned: โ โ (ISR ยท IVA ยท โ โ (RAG over SAT โ โ (P&L, โ
โ double- โ โ txn โ SAT โ โ RESICO ยท US) โ โ + IRS corpus, โ โ balance, โ
โ entry) โ โ account) โ โ DETERMINISTICโ โ cites rules) โ โ ratios) โ
โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ
- Capture โ Add a transaction by typing it, snapping a receipt (vision OCR), importing a CFDI XML, or uploading a bank/CSV export.
- Classify โ The fine-tuned model maps each transaction to the correct SAT chart-of-accounts code and expense category (deductible? IVA-bearing? which rate?).
- Book โ It is written to a proper double-entry ledger in SQLite โ debits and credits balance.
- Compute โ Ask anything ("what do I owe this month?", "am I profitable?") and the agent calls the deterministic Tax & Finance Engine: ISR, IVA, RESICO rates, financial ratios, break-even, runway, depreciation.
- Ground & explain โ The answer is grounded in the indexed regulation corpus, cites the relevant article, and is explained in plain language with the math shown.
The user-facing features
| Feature | What it does |
|---|---|
| Smart capture | Type, photograph (receipt OCR), import CFDI 4.0 XML, or upload CSV. |
| Auto-categorization | Fine-tuned classifier โ SAT account + deductibility + IVA treatment. |
| Double-entry ledger | Every movement booked as balanced debits/credits in SQLite. |
| Tax dashboard (MX) | Live estimate of monthly ISR and IVA owed; RESICO vs general regime. |
| SAT calendar | Upcoming declaration deadlines and what's due (provisional, DIOT, annual). |
| Financial statements | Estado de Resultados (P&L), Balance General, Cash Flow. |
| Health check | Liquidity ratio, profit margin, break-even point, cash runway, top expenses. |
| Plain-language Q&A | "Can I deduct my laptop?" โ grounded answer citing the rule. |
| ๐บ๐ธ Bonus USA mode | Schedule-C net profit, self-employment tax, federal estimated quarterly tax, sales-tax notes. |
| Export | One-click P&L / ledger to CSV/XLSX for the human accountant or the SAT portal. |
Architecture highlights โ the principles that win
These are lifted directly from what worked in our previous hackathon entry and hardened for finance:
- The model never does arithmetic. Every peso of tax, every ratio, every total comes from a unit-tested deterministic Python engine. The LLM decides which formula to call and explains the result โ it does not compute it. This is the single most important design choice for a financial product and the credible answer to "how do you trust a small model with taxes?"
- Grounded, not guessed. Regulatory answers retrieve from an indexed corpus of SAT / IRS source text and cite the article. If the corpus doesn't support a claim, the agent says so and recommends a human CPA โ it never free-styles tax law.
- Real agent loop, not a wrapper. The model plans, calls typed tools, reads results, and decides the next step (capture โ classify โ book โ compute โ report). The tool layer is the product; the model is the orchestrator.
- One model, many roles. A single ~8B model handles classification, tool-planning, and natural-language explanation โ no redundant downloads, fits the param budget with huge headroom.
- Deterministic where it must be, generative where it helps. Numbers and law: deterministic. Language and judgment: generative. The boundary is the architecture.
- Privacy by default. Financial data is sensitive. The whole thing can run fully local (llama.cpp + on-disk SQLite) โ your books never leave your machine.
Models & parameter budget
| Role | Model | Params | Runtime |
|---|---|---|---|
| Reasoning ยท classification ยท explanation | openbmb/MiniCPM-...-8B (fine-tuned) |
~8B | llama.cpp (GGUF, quantized) |
| Receipt OCR (optional capture) | small vision model / Tesseract fallback | โค4B | local |
Total: ~8B parameters (โค 32B cap โ โ comfortable headroom).
- Why MiniCPM (OpenBMB): strong tool-calling and multilingual (Spanish) performance at 8B, and it makes us eligible for the OpenBMB sponsor award.
- Why llama.cpp + GGUF: runs the whole agent on a laptop with no GPU, unlocking the ๐ Off the Grid and ๐ฆ Llama Champion badges at once.
- Tiny Titan path (optional stretch): ship a โค4B variant (e.g. a 3โ4B fine-tune) as a "lite" mode to compete for the ๐ Tiny Titan special award.
What we fine-tune (๐ฏ Well-Tuned)
We publish a fine-tuned transaction-classification + tool-planning model to the Hub.
- Task 1 โ SAT categorization: map a free-text / OCR'd transaction description ("Uber al cliente", "cafรฉ con proveedor", "licencia Adobe anual") to the correct SAT chart-of-accounts code, deductibility flag, and IVA treatment (16% / 0% / exempt). This is exactly the kind of narrow, high-value task where a fine-tune beats a generic model and a generic model embarrasses itself.
- Task 2 โ tool-call planning: teach reliable, schema-valid function-calling for our engine (the model emits clean JSON tool calls instead of prose).
Dataset: a synthetic-plus-curated set of Mexican transaction descriptions โ SAT codes (generated from the official catรกlogo de cuentas + real anonymized examples), plus tool-call traces. Published as a Hub dataset for the ๐ก Sharing is Caring badge. (We already proved this pipeline: our previous entry fine-tuned a planner on 2,046 instruction pairs.)
Mexican regulation coverage (the core)
| Area | What the engine implements |
|---|---|
| Regimes | RESICO (Personas Fรญsicas), Rรฉgimen de Actividad Empresarial y Profesional, Plataformas Digitales; Personas Morales basics. |
| ISR | Monthly provisional payments; RESICO progressive rate table by income bracket; annual reconciliation estimate. |
| IVA | 16% standard, 0% (border/exports/basic goods), exempt; IVA acreditable vs trasladado; monthly net. |
| Retenciones | ISR/IVA withholdings on professional fees and platform income. |
| CFDI 4.0 | Parse XML invoices โ auto-book income/expenses with the right tax breakdown. |
| Deductibility | Strict vs non-strict deductions, requisitos (CFDI, payment method, business purpose). |
| Obligations calendar | Provisional declarations, DIOT, annual return dates. |
โ ๏ธ Disclaimer (shipped in-app): Cuentas Claras is an educational assistant, not a substitute for a licensed Contador Pรบblico. Tax tables are versioned and dated; the app tells the user to confirm filings with a professional. This honesty is a feature, not a hedge.
๐บ๐ธ Bonus: USA mode
Schedule-C net profit, self-employment tax (15.3%), federal income tax brackets, quarterly estimated tax (Form 1040-ES), and a sales-tax primer for the most common states โ aimed at Mexican freelancers earning USD and US-based gig workers.
Tech stack
- UI: Gradio
6.x, hosted as a Hugging Face Space (hard requirement โ). - Custom frontend (๐จ Off-Brand): a bespoke "ledger book / receipt" aesthetic via
gr.Server+ custom CSS โ monospaced numerals, green-ledger palette, tabbed accountant dashboard โ pushing well past default Gradio. - Inference:
llama.cpp(GGUF) for local-first; Modal endpoint as an optional hosted fallback for the public demo (makes us eligible for the Modal award and keeps the Space responsive under load). - Storage: SQLite (double-entry ledger, per-user, on disk).
- Engine: pure-Python, fully unit-tested tax & finance module (no LLM in the number path).
- Retrieval: lightweight local embedding index over the SAT/IRS corpus (no external API).
- Capture: receipt OCR + CFDI XML parser + CSV importer.
Bonus Quests โ going for all six ๐๏ธ
| Badge | Target | How |
|---|---|---|
| ๐ Off the Grid | โ | Entire agent runs locally on llama.cpp + on-disk SQLite; no cloud API required. |
| ๐ฏ Well-Tuned | โ | Fine-tuned MiniCPM for SAT categorization + tool-planning, published to the Hub. |
| ๐จ Off-Brand | โ | Custom "ledger book" UI via gr.Server + CSS โ not the default Gradio look. |
| ๐ฆ Llama Champion | โ | Model served through the llama.cpp runtime (GGUF, quantized). |
| ๐ก Sharing is Caring | โ | Agent traces + the fine-tune dataset shared publicly on the Hub. |
| ๐ Field Notes | โ | Blog post: "Building a trustworthy small-model accountant โ when NOT to let the LLM do the math." |
Stacking sponsor & special awards (one app, many podiums)
- ๐ฎ OpenBMB Award โ built on MiniCPM.
- ๐ข Modal Award โ hosted inference endpoint on Modal.
- ๐ค Best Agent โ a genuine planโtoolโgroundโexplain loop under the 32B cap.
- ๐๏ธ Bonus Quest Champion โ all six badges on one sash.
- ๐จ Off-Brand Award โ the custom ledger UI.
- ๐ Tiny Titan (stretch) โ optional โค4B "lite" build.
Project structure (planned)
FinanceHelper/
โโโ app.py # Gradio entry point (Space)
โโโ README.md # Space card (this front-matter)
โโโ requirements.txt
โโโ packages.txt
โโโ src/
โ โโโ agent/ # planner, tool registry, agent loop
โ โโโ engine/ # DETERMINISTIC tax & finance math (unit-tested)
โ โ โโโ isr.py
โ โ โโโ iva.py
โ โ โโโ resico.py
โ โ โโโ ratios.py
โ โ โโโ us_tax.py
โ โโโ ledger/ # SQLite double-entry store
โ โโโ capture/ # OCR, CFDI XML parser, CSV importer
โ โโโ retrieval/ # SAT/IRS corpus index + citation
โ โโโ models/ # llama.cpp loader, prompts
โ โโโ ui/ # gr.Server custom frontend + CSS
โ โโโ config.py
โโโ modal_app/ # optional hosted inference endpoint
โโโ data/
โ โโโ regulation/ # SAT + IRS source corpus (dated, versioned)
โ โโโ catalogo_cuentas/ # SAT chart of accounts
โ โโโ sample/ # demo ledger for the video
โโโ scripts/
โ โโโ build_classifier_dataset.py
โ โโโ train_classifier.py
โโโ tests/ # engine correctness tests (gold tax cases)
Implementation roadmap (to June 15)
- Engine first (the trust foundation). Build and unit-test ISR / IVA / RESICO / ratios against hand-computed gold cases. No model involved yet.
- Ledger + capture. SQLite double-entry store; CSV import; CFDI XML parser; receipt OCR.
- Agent loop. Tool registry + planner; wire MiniCPM via llama.cpp; schema-valid tool calls.
- Retrieval + citations. Index SAT/IRS corpus; ground answers; "cite or abstain" guardrail.
- Fine-tune + publish. Train the SAT classifier; push model + dataset to the Hub.
- Custom UI.
gr.Serverledger-book frontend; tax dashboard; statements; export. - USA bonus mode. Schedule-C / SE-tax / 1040-ES estimator.
- Polish + Modal fallback + deploy to the Space.
- Deliverables. Demo video, social post, blog (Field Notes), shared traces.
Deliverables checklist (hackathon submission)
- Public Gradio Space under the hackathon org.
- Demo video โ capture a receipt โ book it โ "what do I owe this month?" โ grounded answer.
- Social-media post showing the ledger UI and the live tax estimate.
- Fine-tuned model + dataset on the Hub (๐ฏ + ๐ก).
- Blog post / report (๐).
- Agent traces shared on the Hub (๐ก).
- A real person used it during the hack window (๐ก Backyard AI evidence).
Risks & mitigations
| Risk | Mitigation |
|---|---|
| Tax math must be exact | Deterministic, unit-tested engine; model is barred from the number path. |
| Tax law is nuanced / changes | Dated, versioned corpus; "cite or abstain"; explicit "confirm with a CPA" disclaimer. |
| Small model tool-calling reliability | Fine-tune specifically on schema-valid tool calls; strict JSON parsing with graceful fallback. |
| Space latency / ZeroGPU limits | llama.cpp quantized local path + optional Modal endpoint for the public demo. |
| Sensitive financial data | Local-first by default; data stays in on-disk SQLite; no required cloud calls. |
Submission for the Hugging Face "Small Models, Big Adventures" Hackathon ยท June 5โ15, 2026. Track: ๐ก Backyard AI. Going for all six bonus badges, plus OpenBMB / Modal / Best Agent.