Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌟 KHATA AI - Intelligent Invoice & Inventory Management System

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.


✨ Core Features

πŸ€– AI-Powered Billing Assistant

  • 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").

πŸ“„ Document Intelligence (OCR & Digitization)

  • 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.

πŸ“Š Real-time Interactive Dashboard

  • 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.

πŸ” Secure & Scalable Backend

  • 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.

πŸ—οΈ Architecture Overview

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]
Loading

πŸ› οΈ Technology Stack

  • 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)

πŸ” Technical Deep-Dive

1. Application Controller (app.py)

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.

2. Google Gemini AI Engine (ai_service.py)

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.

3. Database Schemas (models.py)

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"
Loading

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.

4. Interactive Drawing Canvas (base.html / UI)

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 Comparison Matrix

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)

πŸš€ Installation & Local Execution

Prerequisites

1. Clone the Repository

git clone https://github.com/GuptaNandinii/KHATA-AI.git
cd KHATA-AI

2. Create Virtual Environment

python -m venv venv
# On MacOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment Variables

Create 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_name

5. Initialize Database & Seed Dummy Data

Create the SQL tables, run migrations, and inject initial demo profiles:

python seed_db.py

6. Run the Server

python app.py

Open your browser and navigate to http://127.0.0.1:5000.


πŸ”‘ Demo Credentials

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
  • Admin Account:
    • Email: admin@admin.com
    • Password: admin
  • Customer Account:
    • Email: customer@example.com
    • Password: password

🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page to get involved.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is open-source and available under the MIT License.

About

A smart, AI-powered invoice and inventory management system for SMEs. Features natural language billing, scanned receipt OCR digitization, real-time analytics, and role-based portals built with Flask.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages