A FastAPI backend that processes mathematical expressions from images using Google's Gemini AI model.
- Python 3.11+
- Google Gemini API Key
-
Clone and install dependencies
git clone <your-repo-url> cd smartsum-be pip install -r requirements.txt
-
Create
.envfileGEMINI_API_KEY=your_gemini_api_key_here ENV=dev SERVER_URL=localhost PORT=8900
-
Run the server
python main.py
Server runs at:
http://localhost:8900
GET /
GET /healthPOST /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
}
]
}- Basic Math:
2 + 3 * 4,5 / 6(follows PEMDAS) - Equations:
x^2 + 2x + 1 = 0,3y + 4x = 0 - Variable Assignment:
x = 4,y = 5 - Word Problems: Visual math problems in drawings
- Abstract Concepts: Identifies concepts from drawings
- Supports CORS for
localhost:3000,localhost:5173, etc. - Auto-reload enabled in dev mode
- Push to GitHub
- Connect repo to Render
- Set environment variables:
GEMINI_API_KEY: Your API keyENV:prodALLOWED_ORIGINS: Your frontend domain
Build Command: pip install -r requirements.txt
Start Command: uvicorn main:app --host 0.0.0.0 --port $PORT
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
- Dev: Allows common local dev servers
- Prod: Configured via
ALLOWED_ORIGINSenv var
| 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) | - |
Visit http://localhost:8900/docs for interactive Swagger UI
# 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": {}}'- Frontend: https://smart-calc-ai.vercel.app
- API Docs: Visit
/docsendpoint for interactive documentation
Made with โค๏ธ AK-RAJAK