A smart, modern billing, inventory, and customer management system engineered specifically for small-to-medium businesses. Powered by Flask, SQLAlchemy, Google Gemini 1.5 Flash, and Cloudinary, KHATA AI revolutionizes the way businesses handle their ledgers.
It features an interactive real-time dashboard, role-based access portals, and a state-of-the-art AI Billing Assistant that supports natural language voice and text commands, scanned bill OCR digitization, canvas markup annotations, and persistent document notes.
- Live Demo: https://invoice-system-ai.onrender.com
- Developer Portfolio: github.com/GuptaNandinii
- Natural Language Processing: Chat or speak to the AI Assistant to generate invoices, update inventory, or query customer balances (e.g., "Make an invoice for Rahul for 2 laptops").
- Multilingual Voice Support: Processes Hinglish/Hindi audio commands via Web Speech API and translates them into actionable data points.
- Contextual Memory: Remembers conversational context across multiple turns (e.g., "Add a mouse to that bill too").
- Automated Scanned Bills: Upload images of paper bills or receipts. The system automatically extracts the vendor name, date, line items, and total amount.
- Inventory Syncing: Items extracted from paper bills automatically increment your digital product inventory.
- Interactive Canvas Viewer: Draw, annotate, zoom, and pan across scanned documents directly in the browser. Save and download marked-up versions.
- Dynamic Analytics: View daily/weekly revenue trends, top-selling products, and outstanding payments.
- Metric Toggles: Exclude specific scanned bills or expenses from your core KPI calculations dynamically without deleting the records.
- Role-Based Portals: Distinct secure portals for Sellers (Business Owners), Customers, and Administrators.
- Smart Compression: Pillow-based edge processing compresses high-resolution scanned documents by up to 90% before securely uploading them to Cloudinary.
graph TD
User([Sellers & Customers]) <-->|HTTP Requests| Flask[Flask Server: app.py]
Flask <-->|SQLAlchemy ORM| DB[(SQLite / MySQL Database)]
Flask <-->|Google GenAI SDK| Gemini[Gemini 1.5 Flash AI Engine]
Flask <-->|Cloudinary API| Cloudinary[Cloudinary Cloud Storage]
Flask <-->|Pillow Pipeline| PIL[Pillow Processing Engine]
- Backend: Python 3.10+, Flask, SQLAlchemy, Pillow
- Frontend: HTML5, CSS3, JavaScript, HTML5 Canvas API, Web Speech API
- Database: SQLite (Development) / MySQL (Production)
- AI & Machine Learning: Google Generative AI (Gemini 1.5 Flash)
- Cloud Storage: Cloudinary (with secure local fallback)
Handles role-based routes (@login_required and @role_required). Manages dynamic database migrations, missing column fallback creations, and API endpoints for Ajax metric syncing. Coordinates the secure file upload and compression pipeline (max 1600px width, Q=75 JPEG) for Cloudinary.
Analyzes images/PDFs utilizing genai.GenerativeModel with strict JSON schema structures (BillData). It reliably maps free-form conversational text to SQL tables and performs Levenshtein fuzzy string-matching for non-exact product name lookups.
erDiagram
SELLER ||--o{ CUSTOMER : "manages"
SELLER ||--o{ PRODUCT : "owns"
SELLER ||--o{ INVOICE : "issues"
CUSTOMER ||--o{ INVOICE : "receives"
INVOICE ||--|{ INVOICE_ITEM : "contains"
SELLER ||--o{ ACTIVITY : "triggers"
Key isolation features include is_bill flags to separate expenses from sales ledgers, and is_synced toggles to dictate whether digitized items populate primary databases.
Implements an HTML5 <canvas> coordinate space allowing for complex user annotations. Features Pan, Zoom (up to 500%), Rotate functionality, and base64 Data URL export downloads.
| Feature | Sales Invoices (Income) | Scanned Bills (Expenses) |
|---|---|---|
| Tab Placement | Invoices Tab (Sales) | Invoices Tab (Scanned Bills) |
| Creation Method | Manual Form / AI Voice Command | OCR Image Upload & Auto-Digitization |
| Stock Modification | Depletes Product Inventory | Increments Product Inventory |
| Business Metrics | Always included in revenue KPIs | Optional (Toggleable switch on each bill) |
| File Annotations | N/A | Supported (Interactive Drawing Canvas) |
| Persistent Notes | N/A | Supported (Sidebar Editor & DB Storage) |
- Python 3.10+
- SQLite (default) or MySQL
- Google Gemini API Key
- Cloudinary Account (optional, falls back to local storage automatically)
git clone https://github.com/GuptaNandinii/KHATA-AI.git
cd KHATA-AIpython -m venv venv
# On MacOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the root directory:
# Flask Setup
SECRET_KEY=your_super_secret_key_here
FLASK_ENV=development
# Google Gemini API
GEMINI_API_KEY=your_gemini_api_key_here
# Cloudinary Setup (Optional - omit to use local storage)
CLOUDINARY_URL=cloudinary://your_api_key:your_api_secret@your_cloud_nameCreate the SQL tables, run migrations, and inject initial demo profiles:
python seed_db.pypython app.pyOpen your browser and navigate to http://127.0.0.1:5000.
To explore the application locally without creating an account, use the following pre-seeded credentials:
- Seller Account (Full access to AI Assistant, Dashboard, and Invoices):
- Email:
demo@invoiceai.com - Password:
demo123
- Email:
- Admin Account:
- Email:
admin@admin.com - Password:
admin
- Email:
- Customer Account:
- Email:
customer@example.com - Password:
password
- Email:
Contributions, issues, and feature requests are welcome! Feel free to check the issues page to get involved.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open-source and available under the MIT License.