Multi-modal AI tutor that solves handwritten and typed math problems with step-by-step pedagogical explanations.
Supports: Algebra ยท Calculus ยท Geometry ยท Trigonometry ยท Statistics ยท Arithmetic
Features โข Demo โข Installation โข Usage โข Architecture โข Contributing
MathGPT is an advanced, multi-modal AI application that acts as an expert mathematics tutor. Built on a split-model architecture powered by the Groq Inference Engine, it instantly processes both handwritten/printed images and complex textual math equations to deliver structured, step-by-step pedagogical solutions โ not just final answers.
Whether a student uploads a photo of a textbook problem or types out an algebraic equation, MathGPT identifies the right solving strategy, walks through the derivation, and presents a clear final result.
| Feature | Description |
|---|---|
| ๐ผ๏ธ Multi-Modal Input | Accepts raw text queries or image uploads (photos of equations, word problems, handwritten work). |
| โก Dual-Engine Processing | State-of-the-art vision LLMs handle direct image comprehension, with an autonomous text-based fallback for reliability. |
| ๐ Robust OCR Fallback Pipeline | OpenCV-based preprocessing (grayscale conversion, cubic upscaling, denoising, adaptive thresholding) paired with Tesseract OCR ensures uptime if primary vision APIs hit rate limits. |
| ๐ง Intelligent Math Filter | Regex-driven heuristic classification ensures only math-related queries reach the LLM, protecting compute resources from arbitrary/off-topic input. |
| ๐ Pedagogical Step-by-Step Explanations | Enforces systematic derivation, variable identification for word problems, and a clearly highlighted final answer. |
| Layer | Technology |
|---|---|
| Frontend UI | Streamlit โ Python-native reactive dashboard framework |
| Inference Engine | Groq Cloud API โ ultra-low-latency LLM hosting |
| Text Solver LLM | Meta Llama 3.3 70B Versatile (low temperature for deterministic precision) |
| Vision Solver LLM | Meta Llama 4 Scout 17B (16e-Instruct) |
| Computer Vision / OCR | OpenCV (cv2) + PyTesseract |
flowchart TD
A[User Input] -->|Text Query| B[Math Filter โ Regex Heuristics]
A -->|Image Upload| C[Vision LLM: Llama 4 Scout]
C -->|Rate Limited / Fails| D[OpenCV Preprocessing]
D --> E[Tesseract OCR]
E --> B
B -->|Valid Math Query| F[Text LLM: Llama 3.3 70B]
B -->|Not Math| G[Reject / Prompt User]
F --> H[Step-by-Step Solution]
C -->|Success| H
- Python 3.10 or higher
- Tesseract OCR installed on your system
- A Groq API Key
git clone https://github.com/jawad-hua/MathGPT.git
cd MathGPTpython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txt| OS | Command |
|---|---|
| Ubuntu/Debian | sudo apt install tesseract-ocr |
| macOS | brew install tesseract |
| Windows | Download installer from UB-Mannheim/tesseract |
Create a .streamlit/secrets.toml file in the project root:
GROQ_API_KEY = "your_groq_api_key_here"
โ ๏ธ This file is already listed in.gitignoreโ never commit your real API key.
streamlit run app.pyThe app will be available at http://localhost:8501.
- Launch the app with
streamlit run app.py. - Choose your input method:
- Text: Type any math equation or word problem directly.
- Image: Upload a photo or screenshot of a handwritten/printed problem.
- MathGPT validates the query, routes it through the appropriate model, and returns a full step-by-step solution with the final answer clearly marked.
Input (text):
Solve for x: 2xยฒ - 5x - 3 = 0
Output:
Step 1: Identify the quadratic equation in standard form axยฒ + bx + c = 0
a = 2, b = -5, c = -3
Step 2: Apply the quadratic formula
x = (-b ยฑ โ(bยฒ - 4ac)) / 2a
Step 3: Substitute values
x = (5 ยฑ โ(25 + 24)) / 4 = (5 ยฑ 7) / 4
Final Answer: x = 3 or x = -1/2
MathGPT/
โโโ .streamlit/
โ โโโ secrets.toml # Groq API key & local secrets (gitignored)
โโโ app.py # Streamlit entry point โ UI + solving logic
โโโ packages.txt # System-level dependencies (e.g. tesseract-ocr)
โโโ requirements.txt # Python dependencies
โโโ readme.md
โโโ .gitignore
๐
secrets.tomlholds yourGROQ_API_KEYand is excluded from version control via.gitignore. Never commit this file.
- Support for graph plotting (functions, derivatives, integrals)
- Multi-language support (Urdu/English bilingual explanations)
- Export solutions as PDF
- Conversation history & saved problem sets
- LaTeX rendering for cleaner equation display
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure to update tests as appropriate and follow the existing code style.
This project is licensed under the MIT License โ see the LICENSE file for details.
Muhammad Jawad
โญ If you find this project useful, consider giving it a star on GitHub!



