Skip to content

Latest commit

ย 

History

13 Commits

Folders and files

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

Repository files navigation

KalaSutra AI Logo

KalaSutra AI

Kala (เค•เคฒเคพ) = Art ย ยทย  Sutra (เคธเฅ‚เคคเฅเคฐ) = Formula

An AI-powered educational platform that transforms mathematical equations into animated Indian cultural geometry โ€” with a built-in multilingual AI Teacher powered by Gemma.


Python FastAPI React TypeScript Gemma License: MIT


๐Ÿ““ Kaggle Writeup ย ยทย  ๐ŸŽฌ Demo Video


"280 million Indian students study in regional languages โ€” yet almost every math visualisation tool speaks only English and uses only Western metaphors. KalaSutra AI changes that."


๐Ÿ“Œ Table of Contents (click to expand)

๐ŸŽฏ The Problem We Solve

Mathematics is the single most failed subject across Indian board exams. Three systemic gaps make it worse:

Gap Impact
๐Ÿ”‡ Abstraction Static textbooks cannot show how changing sin(4ฮธ) โ†’ sin(8ฮธ) transforms the geometry. Students memorise formulas without understanding shapes.
๐ŸŒ Language Barrier 280M+ students study in Hindi, Bengali, Tamil, or Telugu โ€” yet quality visual math resources exist almost exclusively in English.
๐ŸŽญ Cultural Disconnect Global EdTech defaults to Western visual metaphors. Indian students don't see their own cultural geometry (Rangoli, Kolam, Mandala) reflected in math education.

Who Is This For?

Segment Users
Primary Class 9โ€“12 students ยท JEE / NEET aspirants ยท Engineering undergraduates
Secondary Mathematics teachers ยท Coaching institutes ยท Parents

๐Ÿ’ก Our Solution

KalaSutra AI is a full-stack educational tool that turns any mathematical equation into an interactive learning experience rooted in Indian culture.

A student types an equation. The system responds with:

Equation  โ†’  Animated Cultural Artwork  +  AI Teacher Explanation  +  Quiz  +  Real-Life Connection
                (Rangoli / Mandala /         (in their own             (2 auto-generated    (contextualised
                 Kolam / Alpana)              language)                 questions)           analogy)

This is not a chatbot. This is not "Chat with PDF". This is a purpose-built learning loop โ€” equation โ†’ visualisation โ†’ explanation โ†’ assessment โ€” in one seamless interface.


โญ Key Features

Feature What It Does
๐Ÿงฎ Equation Interpreter SymPy-powered parser handles polar, parametric, and algebraic equations. Extracts variables, functions, and symmetry order automatically.
๐ŸŽจ Cultural Geometry Generator Renders equations as Rangoli, Mandala, Kolam, or Alpana artwork โ€” culturally familiar Indian geometric art forms.
๐ŸŽฌ Animated SVG Canvas Framer Motion draws each geometric layer sequentially โ€” circles, petals, dots, spirals, polygons โ€” creating a compelling visual reveal.
๐Ÿง  AI Teacher Panel Gemma explains why the shape looks the way it does, in the student's own language. Concise (โ‰ค40 words), pedagogically targeted.
๐ŸŒ 5 Indian Languages English ยท Hindi (เคนเคฟเค‚เคฆเฅ€) ยท Bengali (เฆฌเฆพเฆ‚เฆฒเฆพ) ยท Tamil (เฎคเฎฎเฎฟเฎดเฏ) ยท Telugu (เฐคเฑ†เฐฒเฑเฐ—เฑ)
๐Ÿ“ AI Quiz Generator 2 auto-generated questions per equation (MCQ + short answer) to reinforce understanding immediately.
๐Ÿ”— Real-Life Connections Contextualises every concept โ€” satellite dishes, clock gears, manhole covers โ€” so math feels tangible.
๐Ÿ”„ Parameter Playground Change any coefficient and instantly see how symmetry, petal count, and geometry evolve.
๐Ÿ“ฅ SVG Export Download the generated artwork as a production-quality scalable vector file.

๐Ÿงช Quick Start โ€” Try It Now

Once the app is running, paste any of these equations into the KalaSutra Canvas:

Equation What You'll See Recommended Theme
r = sin(8*theta) ๐ŸŒธ 8-petal Polar Rose with 8-fold symmetry Rangoli
r = cos(12*theta) ๐ŸŒบ 12-petal Rose โ€” intricate circular pattern Mandala
r = theta ๐ŸŒ€ Archimedean Spiral โ€” expanding outward Kolam
r = 1 + sin(theta) ๐Ÿ’— Cardioid โ€” heart-shaped curve Alpana
r = sin(theta) * cos(theta) ๐ŸŒผ 4-petal flower Rangoli

๐Ÿ’ก Pro-tip: Change the coefficient of theta (e.g., 8 โ†’ 6 in sin(8*theta)) to watch the symmetry transform in real time!


๐Ÿ— System Architecture

graph TD
    subgraph Browser ["๐ŸŒ React 19 Frontend (Vite + Tailwind)"]
        direction LR
        A["๐Ÿ“ Equation Editor<br/>(Left Pane)"]
        B["๐ŸŽจ SVG Canvas<br/>(Center Pane)"]
        C["๐Ÿ‘จโ€๐Ÿซ AI Teacher<br/>(Right Pane)"]
    end

    subgraph Backend ["โšก FastAPI Backend"]
        direction LR
        D["1๏ธโƒฃ Equation Parser<br/>(SymPy)"]
        E["2๏ธโƒฃ Gemma Engine<br/>(google-genai)"]
        F["3๏ธโƒฃ Response Validator<br/>(Pydantic)"]
    end
    
    G[("๐Ÿง  Gemma 4 26B (MoE)<br/>(gemma-4-26b-a4b-it)")]

    A -->|"HTTP POST<br/>/api/generate"| D
    D -->|"Parsed properties"| E
    E -->|"Prompt + Schema"| G
    G -->|"Structured JSON"| F
    F -->|"Response"| B
    F -->|"Response"| C
    
    classDef frontend fill:#eef2ff,stroke:#6366f1,stroke-width:2px,color:#1e1b4b
    classDef backend fill:#f0fdf4,stroke:#22c55e,stroke-width:2px,color:#14532d
    classDef model fill:#eff6ff,stroke:#3b82f6,stroke-width:3px,color:#1e3a8a
    
    class A,B,C frontend
    class D,E,F backend
    class G model
Loading

Request Flow

Step Phase What Happens
1 Input User enters an equation (e.g., r = sin(8ฮธ)), selects a cultural theme and language.
2 Parse The backend's SymPy-based parser extracts equation type, free variables, trig functions, and symmetry order.
3 Reason Parsed data is sent to Gemma 4 26B (MoE) with a strict Pydantic schema enforcing structured JSON output.
4 Respond Gemma returns a GemmaTeachingResponse โ€” concept, explanation, quiz, real-life connection, and rendering instructions.
5 Render React frontend populates the AI Teacher panel and animates the SVG canvas layer by layer using Framer Motion.

๐Ÿง  How Gemma Powers KalaSutra

Gemma is not a wrapper. It is the reasoning core of the entire application, performing 5 distinct roles in a single structured inference call:

flowchart LR
    A["๐Ÿ“ Parsed<br/>Equation"] --> B{"๐Ÿง  Gemma 4 26B<br/>(Single Inference Call)"}
    
    B --> C["๐Ÿ‘จโ€๐Ÿ”ฌ Mathematician<br/>(Type, Symmetry)"]
    B --> D["๐Ÿ—ฃ๏ธ Teacher<br/>(Multilingual Explanation)"]
    B --> E["๐Ÿ“– Storyteller<br/>(Real-life Analogy)"]
    B --> F["๐Ÿ“ Quiz Creator<br/>(2 Targeted Questions)"]
    B --> G["๐ŸŽจ Geometry Architect<br/>(SVG Layers)"]
    
    C --> H["๐Ÿ“ฆ GemmaTeachingResponse<br/>(Pydantic-Validated JSON)"]
    D --> H
    E --> H
    F --> H
    G --> H

    classDef input fill:#f3f4f6,stroke:#9ca3af,stroke-width:2px,color:#111827
    classDef model fill:#eff6ff,stroke:#3b82f6,stroke-width:3px,color:#1e3a8a
    classDef roles fill:#fdf4ff,stroke:#d946ef,stroke-width:2px,color:#701a75
    classDef output fill:#f0fdf4,stroke:#22c55e,stroke-width:2px,color:#14532d

    class A input
    class B model
    class C,D,E,F,G roles
    class H output
Loading

We enforce deterministic structured output using response_mime_type="application/json" with a strict response_schema=GemmaTeachingResponse Pydantic model. This means every response is machine-parseable and UI-ready โ€” no regex extraction, no post-processing hacks.

Key insight: This architecture cleanly separates reasoning (Gemma) from rendering (React/SVG), keeping the system modular, testable, and language-agnostic.


๐ŸŽฏ Why We Chose Gemma 4 26B MoE

We evaluated every available Gemma variant. Here's why gemma-4-26b-a4b-it won:

Factor Why This Variant Fits
Structured JSON Output Supports response_schema via the Google GenAI SDK โ€” critical for our multi-role output (explanation + quiz + rendering) in a single deterministic call.
Multilingual Strength Strong performance across Hindi, Bengali, Tamil, and Telugu โ€” serving our target audience of 280M+ regional-language students.
MoE Efficiency Activates only 4B of 26B parameters per token โ€” fast inference ideal for an interactive tool where students expect real-time feedback.
Math Reasoning Sufficient depth to analyse polar/parametric equations, extract symmetry properties, and generate pedagogically accurate explanations.
Instruction-Tuned The -it variant reliably follows complex multi-constraint prompts (e.g., "explain in โ‰ค40 words in Tamil while also producing geometry layer instructions").
Why Not Other Variants? (click to expand)
Variant Reason for Rejection
Gemma 2B / 4B Insufficient reasoning depth for math concept extraction + quiz generation + geometry instructions in a single structured call.
Gemma 27B Dense Higher latency per token vs. the 26B MoE variant, with no significant quality gain for our structured-output use case.
Gemma 31B Dense Overkill โ€” the MoE variant offers a better latency/quality tradeoff for interactive educational applications.

๐Ÿ›  Tech Stack

Backend

Technology Version Role
Python 3.9+ Core language
FastAPI Latest REST API framework with auto-generated OpenAPI docs
Pydantic v2 Request / response validation & structured output schema for Gemma
google-genai Latest Official Google GenAI Python SDK
Gemma 4 26B (MoE) gemma-4-26b-a4b-it Primary LLM inference engine
SymPy 1.13+ Symbolic math parsing & equation analysis
Uvicorn Latest ASGI server

Frontend

Technology Version Role
React 19 UI framework
TypeScript 6.0 Type safety across all components
Vite 8 Build tooling & dev server
TailwindCSS 3.4 Utility-first styling
Framer Motion 12 SVG path draw animations
Axios 1.18 HTTP client
Lucide React 1.24 Icon library

๐Ÿ“ Project Structure

KalaSutra AI/
โ”œโ”€โ”€ README.md                      # This file
โ”œโ”€โ”€ LICENSE                        # MIT License
โ”œโ”€โ”€ CODE_OF_CONDUCT.md             # Contributor Covenant v2.1
โ”œโ”€โ”€ CONTRIBUTING.md                # Contribution guidelines
โ”œโ”€โ”€ SECURITY.md                    # Security policy
โ”œโ”€โ”€ logo.png                       # Project logo
โ”‚
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ README.md                  # Backend-specific documentation
โ”‚   โ”œโ”€โ”€ requirements.txt           # Python dependencies
โ”‚   โ”œโ”€โ”€ .env                       # API key (not committed)
โ”‚   โ””โ”€โ”€ app/
โ”‚       โ”œโ”€โ”€ main.py                # FastAPI entry point + CORS
โ”‚       โ”œโ”€โ”€ api/
โ”‚       โ”‚   โ””โ”€โ”€ generate.py        # POST /api/generate endpoint
โ”‚       โ”œโ”€โ”€ gemma/
โ”‚       โ”‚   โ””โ”€โ”€ engine.py          # Gemma inference + prompt engineering
โ”‚       โ”œโ”€โ”€ parser/
โ”‚       โ”‚   โ””โ”€โ”€ equation.py        # SymPy equation parser
โ”‚       โ””โ”€โ”€ schemas/
โ”‚           โ””โ”€โ”€ models.py          # Pydantic models (request / response)
โ”‚
โ””โ”€โ”€ frontend/
    โ”œโ”€โ”€ README.md                  # Frontend-specific documentation
    โ”œโ”€โ”€ index.html                 # HTML entry point + SEO meta tags
    โ”œโ”€โ”€ package.json               # Node.js dependencies
    โ””โ”€โ”€ src/
        โ”œโ”€โ”€ App.tsx                # Root component โ€” layout, state, API calls
        โ”œโ”€โ”€ main.tsx               # Vite entry point
        โ”œโ”€โ”€ index.css              # Tailwind base + Inter font
        โ”œโ”€โ”€ types/
        โ”‚   โ””โ”€โ”€ index.ts           # Shared TypeScript type definitions
        โ””โ”€โ”€ components/
            โ”œโ”€โ”€ EquationEditor.tsx  # Left pane โ€” equation input form
            โ”œโ”€โ”€ Preview.tsx         # Center pane โ€” animated SVG canvas
            โ””โ”€โ”€ AITeacherPanel.tsx  # Right pane โ€” AI Teacher, quiz, symmetry

๐Ÿ’ป Local Development Setup

Prerequisites

Requirement Version
Python 3.9+
Node.js 18+
Gemma API Key Get one free โ†’

1. Clone the Repository

git clone https://github.com/dasouvik122005/KalaSutra-AI.git
cd KalaSutra-AI

2. Backend

cd backend

# Create and activate virtual environment
python -m venv venv
venv\Scripts\activate        # Windows
# source venv/bin/activate   # macOS / Linux

# Install dependencies
pip install -r requirements.txt

# Configure API key
echo GEMINI_API_KEY=your_key_here > .env

# Start the server
uvicorn app.main:app --reload

โš ๏ธ Never commit your .env file. It is already in .gitignore.

Service URL
REST API http://localhost:8000
Swagger UI http://localhost:8000/docs

3. Frontend

# Open a new terminal
cd frontend
npm install
npm run dev

The application will be available at http://localhost:5173


๐Ÿ“ก API Reference

POST /api/generate

Generates teaching materials and rendering instructions for a given equation.

Request

{
  "equation": "r = sin(8*theta)",
  "theme": "rangoli",
  "complexity": "medium",
  "language": "English"
}
Field Type Required Options Default
equation string โœ… Any math expression โ€”
theme string โœ… rangoli ยท mandala ยท kolam ยท alpana โ€”
complexity string โŒ low ยท medium ยท high medium
language string โŒ English ยท Hindi ยท Bengali ยท Tamil ยท Telugu English
Response Body (200 OK) โ€” click to expand
{
  "data": {
    "concept": "Polar Rose Curve",
    "symmetry": "8-fold",
    "difficulty": "Medium",
    "explanation": "The number 8 in sin(8ฮธ) creates 8 petals evenly distributed around the origin.",
    "real_life_connection": "Used in antenna design to produce directional signal patterns.",
    "quiz": [
      {
        "question": "What determines the number of petals in r = sin(nฮธ)?",
        "type": "mcq",
        "options": ["The coefficient n of ฮธ", "The amplitude", "The frequency", "The phase"],
        "answer": "The coefficient n of ฮธ"
      },
      {
        "question": "What symmetry does r = sin(8ฮธ) exhibit?",
        "type": "short_answer",
        "options": null,
        "answer": "8-fold rotational symmetry"
      }
    ],
    "rendering": {
      "canvas": { "width": 1000, "height": 1000, "background": "none" },
      "layers": [
        { "type": "circle", "radius": 220, "stroke": "#e0e7ff", "fill": "none", "stroke_width": 1 },
        { "type": "petal", "count": 8, "radius": 200, "stroke": "#6366f1", "fill": "#e0e7ff", "stroke_width": 1.5 },
        { "type": "dots", "count": 8, "radius": 200, "dot_radius": 5, "stroke": "#4f46e5", "fill": "#4f46e5" }
      ],
      "pattern": "8-Petal Rose Rangoli"
    }
  }
}

GET /health

{ "status": "ok" }

๐ŸŒ Supported Languages

Language Native Script Code
English English English
Hindi เคนเคฟเค‚เคฆเฅ€ Hindi
Bengali เฆฌเฆพเฆ‚เฆฒเฆพ Bengali
Tamil เฎคเฎฎเฎฟเฎดเฏ Tamil
Telugu เฐคเฑ†เฐฒเฑเฐ—เฑ Telugu

๐Ÿค Contributing

Contributions are welcome! Please read our Contributing Guide and Code of Conduct before getting started.

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m 'feat: add your feature'
  4. Push to your branch: git push origin feature/your-feature
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.



Built with โค๏ธ for the Google โ€” Build with Gemma Kaggle Competition

Powered by Gemma 4 26B (MoE) โ€” Bridging Mathematics and Culture, one equation at a time.


Made with Gemma

About

An AI-powered educational platform that transforms mathematical equations into animated Indian cultural geometry (Rangoli, Mandala) with a multilingual AI Teacher powered by Gemma.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages