Skip to content

๐Ÿงฎ AI-powered mathematical expression solver backend built with FastAPI and Google Gemini Flash. Processes images containing math problems, equations, and visual calculations to provide intelligent solutions..

Notifications You must be signed in to change notification settings

Ak-Rajak/SmartSum-AI-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

22 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SmartSum AI Backend

A FastAPI backend that processes mathematical expressions from images using Google's Gemini AI model.

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.11+
  • Google Gemini API Key

Setup

  1. Clone and install dependencies

    git clone <your-repo-url>
    cd smartsum-be
    pip install -r requirements.txt
  2. Create .env file

    GEMINI_API_KEY=your_gemini_api_key_here
    ENV=dev
    SERVER_URL=localhost
    PORT=8900
  3. Run the server

    python main.py

    Server runs at: http://localhost:8900

๐Ÿ“ก API Endpoints

Health Check

GET /
GET /health

Process Image

POST /calculate
Content-Type: application/json

{
  "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
  "dict_of_vars": {"x": 5, "y": 10}
}

Response:

{
  "message": "Image Processed",
  "type": "success",
  "data": [
    {
      "expr": "2 + 3 * 4",
      "result": "14",
      "assign": false
    }
  ]
}

๐Ÿงฎ What It Solves

  1. Basic Math: 2 + 3 * 4, 5 / 6 (follows PEMDAS)
  2. Equations: x^2 + 2x + 1 = 0, 3y + 4x = 0
  3. Variable Assignment: x = 4, y = 5
  4. Word Problems: Visual math problems in drawings
  5. Abstract Concepts: Identifies concepts from drawings

๐ŸŒ Deployment

Local Development

  • Supports CORS for localhost:3000, localhost:5173, etc.
  • Auto-reload enabled in dev mode

Production (Render)

  1. Push to GitHub
  2. Connect repo to Render
  3. Set environment variables:
    • GEMINI_API_KEY: Your API key
    • ENV: prod
    • ALLOWED_ORIGINS: Your frontend domain

Build Command: pip install -r requirements.txt
Start Command: uvicorn main:app --host 0.0.0.0 --port $PORT

๐Ÿ“ Project Structure

smartsum-be/
โ”œโ”€โ”€ apps/calculator/
โ”‚   โ”œโ”€โ”€ route.py          # API endpoints
โ”‚   โ””โ”€โ”€ utils.py          # Gemini AI integration
โ”œโ”€โ”€ constants.py          # Configuration
โ”œโ”€โ”€ main.py              # FastAPI app
โ”œโ”€โ”€ schema.py            # Data models
โ”œโ”€โ”€ requirements.txt     # Dependencies
โ””โ”€โ”€ render.yaml          # Deployment config

๐Ÿ”ง Configuration

CORS

  • Dev: Allows common local dev servers
  • Prod: Configured via ALLOWED_ORIGINS env var

Environment Variables

Variable Description Default
GEMINI_API_KEY Google Gemini API key Required
ENV Environment (dev/prod) dev
PORT Server port 8900
ALLOWED_ORIGINS CORS origins (prod only) -

๐Ÿ› ๏ธ Development

API Documentation

Visit http://localhost:8900/docs for interactive Swagger UI

Testing

# Health check
curl http://localhost:8900/health

# Test calculation (replace with actual base64 image)
curl -X POST http://localhost:8900/calculate \
  -H "Content-Type: application/json" \
  -d '{"image": "data:image/png;base64,...", "dict_of_vars": {}}'

๐Ÿ”— Links


Made with โค๏ธ AK-RAJAK

About

๐Ÿงฎ AI-powered mathematical expression solver backend built with FastAPI and Google Gemini Flash. Processes images containing math problems, equations, and visual calculations to provide intelligent solutions..

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages