Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AYUSH Habba

AI-Powered OCR and Interpretation of Ayurvedic Sanskrit Shlokas

Extract โ€ข Clean โ€ข Interpret

Responsive Web Application for Desktop and Mobile Devices


๐Ÿ“– Overview

AYUSH Habba is an AI-powered web application designed to digitize and interpret Ayurvedic Sanskrit shlokas from scanned images. The system combines Optical Character Recognition (OCR) with Large Language Models (LLMs) to extract Sanskrit text, perform Sanskrit-aware post-processing, reconstruct complete shlokas, and generate structured English interpretations.

Unlike conventional OCR systems that only extract text, AYUSH Habba performs domain-specific processing by identifying Sanskrit content, reconstructing complete verses, and providing contextual Ayurvedic explanations.

The application is built with a responsive user interface, allowing users to access the platform seamlessly from both desktop/laptop and mobile devices.


โœจ Features

  • ๐Ÿ“ท Upload scanned images containing Ayurvedic Sanskrit shlokas

  • ๐Ÿ” OCR using Tesseract OCR with the Sanskrit language model (san.traineddata)

  • ๐Ÿงน Sanskrit-aware OCR post-processing

  • ๐Ÿ“– Automatic reconstruction of complete shlokas

  • ๐Ÿค– AI-powered interpretation using Google Gemini 2.5 Pro

  • ๐ŸŒฟ Generates structured Ayurvedic information including:

    • Simple Meaning
    • Dosha Involved
    • Clinical Context
    • Classical Source (when identifiable)
    • Key Sanskrit Terms with explanations
  • ๐Ÿ“ฑ๐Ÿ’ป Responsive web application compatible with desktop, laptop, and mobile devices

  • โšก REST API built with FastAPI

  • ๐Ÿ“Š OCR evaluation using Character Error Rate (CER)


๐Ÿ—๏ธ System Architecture

                  Scanned Sanskrit Image
                           โ”‚
                           โ–ผ
               Tesseract OCR (san.traineddata)
                           โ”‚
                           โ–ผ
                  Raw OCR Extraction
                           โ”‚
                           โ–ผ
             Sanskrit-aware Text Cleaning
                           โ”‚
                           โ–ผ
                Shloka Reconstruction
                           โ”‚
                           โ–ผ
             Google Gemini 2.5 Pro
                           โ”‚
                           โ–ผ
      Structured English Interpretation
                           โ”‚
                           โ–ผ
                FastAPI Backend API
                           โ”‚
                           โ–ผ
         Responsive Web Application

๐Ÿ“‚ Project Structure

ayush_habba/
โ”‚
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ main.py              # FastAPI application
โ”‚   โ”œโ”€โ”€ ocr.py               # OCR pipeline
โ”‚   โ”œโ”€โ”€ cleaning.py          # Sanskrit-aware text cleaning
โ”‚   โ”œโ”€โ”€ translate.py         # Gemini integration
โ”‚   โ””โ”€โ”€ requirements.txt
โ”‚
โ”œโ”€โ”€ dataset/
โ”‚   โ””โ”€โ”€ images/              # Sample Sanskrit shloka images
โ”‚
โ”œโ”€โ”€ other/
โ”‚   โ”œโ”€โ”€ evaluate_ocr.py      # OCR evaluation script
โ”‚   โ”œโ”€โ”€ evaluation.txt       # Ground truth dataset
โ”‚   โ”œโ”€โ”€ ocr_results.csv
โ”‚   โ””โ”€โ”€ no_post_op_ocr_results.csv
โ”‚
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ .gitignore

โš™๏ธ Technology Stack

Backend

  • Python
  • FastAPI

Frontend

OCR

  • Tesseract OCR
  • Sanskrit Language Model (san.traineddata)
  • Pillow

AI

  • Google Gemini 2.5 Pro
  • Prompt Engineering

Utilities

  • Requests
  • BeautifulSoup4
  • RapidFuzz
  • python-dotenv

๐Ÿ”„ Processing Pipeline

1. Image Upload

The user uploads a scanned image containing one or more Ayurvedic Sanskrit shlokas.

โ†“

2. OCR Extraction

The uploaded image is converted to PNG format and processed using Tesseract OCR with the Sanskrit language model.

The OCR pipeline includes:

  • Automatic image conversion
  • Sanskrit OCR (san)
  • Multiple Page Segmentation Modes (PSM 6 and PSM 7)
  • Automatic fallback when OCR quality is insufficient

โ†“

3. Sanskrit-aware Text Cleaning

The extracted text undergoes domain-specific post-processing to improve OCR quality.

This stage:

  • Filters non-Sanskrit lines
  • Removes OCR artifacts and unwanted symbols
  • Preserves Sanskrit punctuation (เฅค and เฅฅ)
  • Normalizes whitespace
  • Maintains verse structure

โ†“

4. Shloka Reconstruction

Individual OCR lines are grouped into complete Sanskrit shlokas using the verse delimiter (เฅฅ).

โ†“

5. AI Interpretation

Each reconstructed shloka is processed using Google Gemini 2.5 Pro, which generates:

  • Simple English meaning
  • Dosha involved
  • Clinical context
  • Classical source (if identifiable)
  • Explanation of important Sanskrit terminology

โ†“

6. Response Generation

The FastAPI backend returns:

  • Raw OCR text
  • Cleaned Sanskrit text
  • Reconstructed shlokas
  • Structured AI interpretation

The information is then displayed through a responsive web interface optimized for desktop and mobile devices.


๐Ÿ“ก API

Health Check

GET /

Response

{
    "message": "AYUSH OCR backend is running"
}

OCR Endpoint

POST /ocr

Request

Multipart Form Data

Parameter Type Description
file Image Sanskrit shloka image

Supported formats:

  • PNG
  • JPG
  • JPEG

Example Response

{
  "filename": "sample.png",
  "raw_ocr_text": "...",
  "cleaned_sanskrit_text": "...",
  "shlokas": [
    "..."
  ],
  "translations": [
    {
      "sanskrit": "...",
      "translation": {
        "english": "...",
        "source": "gemini"
      }
    }
  ]
}

๐Ÿš€ Installation

Clone the Repository

git clone https://github.com/poorvijn/ayush_habba.git
cd ayush_habba/backend

Create a Virtual Environment

Windows

python -m venv venv
venv\Scripts\activate

Linux/macOS

python3 -m venv venv
source venv/bin/activate

Install Dependencies

pip install -r requirements.txt

Install Tesseract OCR

Install Tesseract OCR on your system and ensure that the Sanskrit language model (san.traineddata) is available in the tessdata directory.

Verify the installation:

tesseract --version

Configure Environment Variables

Create a .env file inside the backend directory.

GEMINI_API_KEY=YOUR_GEMINI_API_KEY

Run the Backend

uvicorn main:app --reload

The backend will start at:

http://127.0.0.1:8000

Swagger API documentation:

http://127.0.0.1:8000/docs

๐Ÿ“Š OCR Evaluation

The repository includes an OCR evaluation framework for measuring recognition accuracy.

The evaluation pipeline:

  • Uses manually annotated Sanskrit ground-truth text
  • Runs OCR on each image
  • Computes Character Error Rate (CER) using Levenshtein Distance
  • Generates CSV reports for analysis

Evaluation resources:

other/
โ”œโ”€โ”€ evaluate_ocr.py
โ”œโ”€โ”€ evaluation.txt
โ”œโ”€โ”€ ocr_results.csv
โ””โ”€โ”€ no_post_op_ocr_results.csv

This framework enables quantitative assessment of OCR performance and the effectiveness of Sanskrit-aware post-processing.


๐Ÿ“š Dataset

The repository contains a curated dataset of scanned Ayurvedic Sanskrit shlokas used for development and OCR evaluation.

The dataset includes:

  • Single-line Sanskrit verse images
  • Multi-line Sanskrit shlokas
  • Ground-truth Sanskrit annotations
  • OCR evaluation resources

๐Ÿ”ฎ Future Enhancements

  • Support for handwritten Sanskrit manuscripts
  • Batch image processing
  • PDF document support
  • Translation into additional languages
  • Improved explanation of Ayurvedic concepts
  • Retrieval-Augmented Generation (RAG) over classical Ayurvedic literature
  • Cloud deployment
  • Enhanced OCR accuracy through fine-tuning

๐Ÿค Contributing

Contributions are welcome.

  1. Fork the repository.
  2. Create a feature branch.
git checkout -b feature-name
  1. Commit your changes.
git commit -m "Add feature"
  1. Push the branch.
git push origin feature-name
  1. Open a Pull Request.

๐Ÿ“œ License

This project is intended for educational and research purposes.


๐Ÿ‘ฅ Authors

Developed as part of the AYUSH Habba project.

Contributors

  • Poorvi J. Nayak
  • Sriveda Aithaal
  • Vibhuti Kalekar
  • Sharanya Rao
  • Delita Tauro

๐Ÿ™ Acknowledgements

  • Google Gemini API
  • Tesseract OCR
  • FastAPI
  • Python Open Source Community
  • Classical Ayurvedic Literature

โญ If you found this project useful, consider giving the repository a star!

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages