Student: Aric Hurkman
Course: CSCI 250
Final Project: AI Math Tutor
Professor: Gheni Abla
The AI Math Tutor is a web-based application that helps students learn mathematics through AI-powered step-by-step solutions, interactive study sessions, and practice quizzes. The application uses the Google Gemini API (FREE tier) with user-provided API keys for secure, personalized tutoring.
- User Authentication: Google Sign-In or simple email login
- Personal API Keys: Each user provides their own Gemini API key (stored locally)
- Problem Solver: Input any math problem and receive detailed, step-by-step solutions
- π Study Mode: Interactive guided learning with progressive hints
- Practice Quizzes: Generate AI-powered practice problems with immediate feedback
- Multiple Topics: Support for algebra, geometry, calculus, trigonometry, statistics, and linear algebra
- Adaptive Difficulty: Choose between easy, medium, hard, or mixed difficulty levels
- Math Symbol Palette: Interactive palette for inserting mathematical symbols and LaTeX commands
- Live LaTeX Preview: Real-time rendering of mathematical notation using KaTeX
- Type any math problem directly into the text area
- Use LaTeX notation for formatted equations (e.g.,
$x^2$or$\frac{1}{2}$) - Interactive math symbol palette with 9 categories (Basic, Algebra, Calculus, Trig, Greek, etc.)
- Live preview shows your math formatted in real-time
- Receive step-by-step solutions with detailed explanations
- All mathematical expressions rendered beautifully with KaTeX
The AI Math Tutor includes an interactive Study Mode where students collaborate with the AI to solve problems step-by-step!
How Study Mode Works:
- Enter a Problem: Type any math problem you want to learn
- AI Breaks It Down: The AI analyzes your problem and creates 3-6 guided steps
- Work Through Steps: Attempt each step yourself - this is where real learning happens!
- Get Progressive Hints: If stuck, request up to 3 increasingly detailed hints per step
- Check Your Work: Submit your answer and get instant, encouraging feedback
- Track Progress: See your overall performance at the end
Study Mode Benefits:
- Active Learning: Don't just see solutions - discover them yourself
- Progressive Hints: From gentle reminders to strong guidance
- Immediate Feedback: Know right away if you're on track
- Encouraging Tone: AI provides supportive feedback even for wrong answers
- Concept Reinforcement: Each step reinforces mathematical concepts
- Generate AI-powered practice problems on any topic
- Choose difficulty level (Easy, Medium, Hard, Mixed)
- Select number of questions (1-10)
- Receive immediate feedback on your answers
- Track your score and performance
- Review correct answers with explanations
| Technology | Purpose |
|---|---|
| Python 3.8+ | Programming language |
| Flask | Web framework for REST API |
| Flask-CORS | Cross-origin resource sharing |
| Google Generative AI SDK | Gemini API integration (FREE!) |
| Technology | Purpose |
|---|---|
| HTML5/CSS3 | Structure and styling |
| React 18 | UI framework (loaded via CDN) |
| Tailwind CSS | Utility-first styling |
| KaTeX | Mathematical notation rendering |
| Google Identity Services | OAuth 2.0 authentication (optional) |
| Lucide Icons | Icon library |
Before running the application, ensure you have:
- Python 3.8 or higher installed
- A Google Gemini API key (FREE - get one at https://aistudio.google.com/apikey)
- A modern web browser (Chrome, Firefox, Safari, or Edge)
Ensure you have all project files in a directory:
ai-math-tutor/
βββ server.py # Backend Flask server with all API endpoints
βββ index.html # Frontend React application
βββ requirements.txt # Python dependencies
βββ .env # Environment configuration (optional Google Client ID)
βββ .gitignore # Git ignore rules
βββ README.md # This file
Open a terminal/command prompt in the project directory and run:
pip install -r requirements.txtCreate a .env file for optional Google OAuth:
# Optional: Google OAuth (for Google Sign-In button)
GOOGLE_CLIENT_ID=your-client-id-here.apps.googleusercontent.com
# If you don't want Google Sign-In, just leave this file empty or don't create itNote: Google OAuth is optional. The app works perfectly with email/name login alone.
In the terminal, run:
python server.pyYou should see output like:
============================================================
AI Math Tutor - Backend Server
============================================================
Powered by Google Gemini (Users provide their own API key)
Open your browser and go to:
http://localhost:5000
Features:
β Google Sign-In authentication
β User-provided Gemini API keys
β Step-by-step math solutions
β Interactive practice quizzes
β STUDY MODE - Interactive guided learning
============================================================
Open your web browser and go to:
http://localhost:5000
- Sign in using Google Sign-In or enter your name and email
- Get a FREE Gemini API key at: https://aistudio.google.com/apikey
- Enter your API key when prompted
- Start learning!
- Click the "Solver" tab
- Enter your math problem in the text box
- Use the Math Symbols palette to insert special characters (β, β«, Ο, etc.)
- Toggle Live Preview to see your math rendered in real-time
- Click "Solve Problem"
- View the step-by-step solution with LaTeX-rendered math
Example Problems:
Solve for x: 2x + 5 = 13Find the derivative of f(x) = xΒ³ + 2xΒ² - 5x + 3Calculate the area of a triangle with base 8 and height 12Simplify: (3xΒ² + 2x - 1) + (xΒ² - 4x + 5)
LaTeX Notation Examples:
- Fractions:
$\frac{1}{2}$displays as Β½ - Square roots:
$\sqrt{x}$displays as βx - Exponents:
$x^2$displays as xΒ² - Integrals:
$\int x dx$displays as β«x dx
- Click the "Study" tab
- Enter a math problem you want to learn
- Click "Start Learning"
- Work through each step:
- Read the objective for the current step
- Enter your answer in the input field (with live LaTeX preview!)
- Click "Check Answer" to verify
- Use "Need a Hint?" if stuck (up to 3 hints per step)
- Progress through all steps to complete the session
- Review your performance summary
- Click the "Quiz" tab
- Select a math topic (Algebra, Geometry, Calculus, etc.)
- Choose a difficulty level (Easy, Medium, Hard, Mixed)
- Set the number of questions (1-10)
- Click "Start Quiz"
- Answer each question and submit
- Receive immediate feedback and see your final score
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Serve frontend application |
/api/health |
GET | Health check and feature status |
/api/config |
GET | Frontend configuration |
/api/verify-key |
POST | Validate Gemini API key |
/api/solve |
POST | Solve a math problem (text input) |
| Endpoint | Method | Description |
|---|---|---|
/api/quiz/generate |
POST | Generate quiz questions |
/api/quiz/evaluate |
POST | Evaluate student answer |
| Endpoint | Method | Description |
|---|---|---|
/api/study/start |
POST | Start a study session |
/api/study/hint |
POST | Get a hint for current step |
/api/study/check |
POST | Check student's step answer |
The AI Math Tutor supports LaTeX notation for beautiful mathematical formatting:
Wrap expressions in single dollar signs: $x^2 + 5$
Wrap expressions in double dollar signs for centered display: $$\int_0^1 x^2 dx$$
| Symbol | LaTeX | Display |
|---|---|---|
| Fraction | $\frac{a}{b}$ |
a/b |
| Square Root | $\sqrt{x}$ |
βx |
| Exponent | $x^2$ |
xΒ² |
| Subscript | $x_1$ |
xβ |
| Sum | $\sum_{i=1}^{n}$ |
Ξ£ |
| Integral | $\int_a^b$ |
β« |
| Limit | $\lim_{x \to 0}$ |
lim |
| Greek Letters | $\alpha, \beta, \gamma$ |
Ξ±, Ξ², Ξ³ |
- API keys are stored locally in the browser's localStorage
- API keys are never sent to our servers - they go directly to Google's Gemini API
- No file uploads - avoiding rate limit issues with free tier API keys
- For production deployment, use HTTPS and proper authentication
- Make sure your Gemini API key is correct
- Get a free key at: https://aistudio.google.com/apikey
- Check that the key has no extra spaces
- Ensure math expressions are wrapped in
$...$for inline or$$...$$for display - Check browser console for KaTeX errors
- Try refreshing the page
- Ensure you have a stable internet connection
- Try with a simpler math problem first
- Check the browser console for error messages
- Ensure you have a stable internet connection
- Try selecting a different topic or difficulty
If you see "Rate limit exceeded" errors:
- Wait 60 seconds before trying again
- Get a fresh API key from https://aistudio.google.com/apikey
- Use the Settings (βοΈ) button to update your API key
- Avoid making too many requests in quick succession
If Google Sign-In shows errors:
- Just use email/name login instead (works perfectly!)
- Or follow setup guide in Google Cloud Console
- Or remove
GOOGLE_CLIENT_IDfrom.envto hide the Google button
ai-math-tutor/
β
βββ server.py # Flask backend server
β βββ API endpoints # /api/solve, /api/quiz/*, /api/study/*
β βββ System prompts # Instructions for Gemini AI
β βββ JSON cleaning # Response parsing and validation
β βββ Error handling # Comprehensive error responses
β
βββ index.html # Frontend React application
β βββ Login screen # Google Sign-In or email authentication
β βββ Problem Solver # Text input with LaTeX support
β βββ Study Mode # Interactive guided learning
β βββ Quiz Mode # Practice problems with scoring
β βββ Math Symbol Palette # Clickable math symbols & LaTeX
β βββ MathText component # KaTeX rendering
β βββ Settings Modal # Update API key without logout
β βββ Styling # Tailwind CSS + custom styles
β
βββ requirements.txt # Python dependencies
βββ .env # Environment configuration (optional)
βββ .gitignore # Git ignore rules
βββ README.md # Documentation (this file)
This project demonstrates:
- LLM Integration: Working with Google's Gemini API
- Web Development: Full-stack application with Flask and React
- User Authentication: Multiple authentication methods
- API Design: RESTful endpoints with proper error handling
- Frontend Skills: Modern React with hooks and component design
- Mathematical Notation: LaTeX rendering with KaTeX
- Educational Technology: Interactive learning features
- Flask Documentation
- Google Gemini API Documentation
- React Documentation
- Tailwind CSS Documentation
- KaTeX Documentation
- LaTeX Math Symbols
- Removed file upload feature (optimized for free tier API usage)
- Enhanced LaTeX support with live preview
- Improved math symbol palette
- Fixed Google OAuth integration
- Added settings modal for API key management
- Optimized for stable, reliable demos
- Fixed JSON parsing for markdown-wrapped Gemini responses
- Fixed LaTeX backslash escaping for proper rendering
- Added LaTeX category to Math Symbol Palette
- Improved error handling and fallback responses
- Initial release with Problem Solver, Study Mode, and Quiz Mode
- Google OAuth and email authentication
- KaTeX mathematical notation rendering
- Math Symbol Palette with 8 categories
This project was created for educational purposes as part of CSCI 250 coursework at California State University San Marcos.
- Professor Gheni Abla for project guidance and requirements
- Google for the Gemini API (free tier)
- The React, Flask, and KaTeX communities for excellent documentation
- Khan Academy for inspiration on math education approaches
With a paid Gemini API key, you could add:
- File upload support (images, PDFs, Word documents)
- Handwriting recognition
- Graph plotting and visualization
- Multi-page document processing
- Batch problem solving
For this academic project, the text-based approach provides a solid, reliable foundation that works perfectly with the free API tier.
Your AI Math Tutor is complete and ready for demonstration:
- β Clean, professional interface
- β Multiple learning modes
- β Reliable performance with free tier
- β Full LaTeX support
- β Interactive features
- β Comprehensive error handling
Good luck with your presentation! π