An intelligent AI tutoring platform built with FastAPI, Streamlit, LangChain, and Groq, with user authentication and progress tracking powered by PostgreSQL.
- ChatGPT-style AI Tutor (
/tutor/ask): Engage in natural language conversations with an AI assistant for learning and doubt clarification. - Auto-generated MCQ Quizzes (
/quiz/generate): Generate subject-wise multiple-choice quizzes with configurable numbers of questions. - File-based Doubt Solving (
/doubt/solve): Upload documents (PDFs, TXT, images) and ask questions directly related to their content. - User Authentication (Sign Up/Login): Securely register and log in to personalized accounts.
- Personalized Progress Tracking (
/tracker/*): Track your quiz scores and performance over time, accessible only to logged-in users. - Persistent Chat History: Previous conversations are saved and loaded for logged-in users.
- FastAPI: A modern, fast (high-performance) web framework for building the backend API.
- Streamlit: The framework for creating the interactive web-based user interface.
- LangChain: A framework for developing applications powered by large language models.
- Groq: Provides fast inference for large language models (Llama 3, Mixtral) used for tutoring and quiz generation.
- PostgreSQL: A powerful open-source relational database for storing user data, chat history, quiz attempts, and progress.
- Psycopg2-binary: The PostgreSQL adapter for Python.
- Passlib (bcrypt): Used for secure password hashing and verification.
- Python-jose: (For JWT) Recommended for secure token generation and validation in
auth_routes.py. - Pydantic: Data validation and settings management.
- Pandas & Altair: For data manipulation and interactive visualizations in the progress tracker.
- PyMuPDF (fitz) & Pillow + PyTesseract: For text extraction from PDF and image files for the doubt solver.
To run this project on your local machine without Docker, you'll need Python, PostgreSQL, and Tesseract OCR installed.
-
Prerequisites:
- Python 3.8+: Install from python.org.
- PostgreSQL: Install a PostgreSQL server locally (e.g., via PostgreSQL Downloads or a tool like PgAdmin).
- Tesseract OCR Engine: Install Tesseract OCR for your operating system.
- Windows: Download installer from Tesseract-OCR GitHub.
- macOS:
brew install tesseract - Linux (Debian/Ubuntu):
sudo apt-get install tesseract-ocr - Ensure Tesseract is added to your system's PATH.
-
Clone the Repository:
git clone https://github.com/gyan007/AI-Tutor-Platform.git cd AI-Tutor-Platform -
Create and Activate a Virtual Environment:
python -m venv venv # On Windows: .\venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install Dependencies:
pip install -r requirements.txt
Make sure your
requirements.txtis up-to-date with all the libraries listed in the "Tech Stack" section. -
Create
.envfile: In the root directory of the project, create a file named.envand add your API keys and secrets. This file is ignored by Git and keeps your secrets safe.# .env # Groq API Key for LLM access GROQ_API_KEY=sk_your_groq_api_key_here # Database connection string for local PostgreSQL DATABASE_URL=postgresql://user:password@localhost:5432/your_local_db_name # Secret key for JWT token signing (FastAPI backend) SECRET_KEY=your_long_random_secret_for_jwt_signing # Streamlit secret for session state management STREAMLIT_SECRET_KEY=your_long_random_streamlit_secret
Replace placeholders with your actual keys and desired database credentials (user/password/db name for your local PostgreSQL instance).
-
Update
ai_tutor_platform/data/config.ini: This file primarily serves as a fallback or for non-sensitive defaults. Ensure it aligns with your environment.# ai_tutor_platform/data/config.ini [GENERAL] llm_model = llama3-8b-8192 ; Default Groq model temperature = 0.7 api_base = https://api.groq.com/openai/v1 ; api_key = YOUR_GROQ_API_KEY_HERE ; Keep this commented or as placeholder for security
-
Initialize Local Database Schema:
- Start your local PostgreSQL server.
- Connect to your local database (e.g., using
psqlor PgAdmin) and run theCREATE TABLEandCREATE INDEXSQL scripts forusers,chat_history,file_doubts,quiz_attempts, anduser_progress. (These scripts were provided in previous responses).
-
Run FastAPI Backend: Open a new terminal window, activate your virtual environment, navigate to the project root, and run:
export PYTHONPATH=$PYTHONPATH:./ai_tutor_platform # For Linux/macOS # On Windows: set PYTHONPATH=%PYTHONPATH%;.\ai_tutor_platform uvicorn ai_tutor_platform.main_api:app --host 0.0.0.0 --port 8000 --reload
- The
--reloadflag is useful for local development, automatically restarting the server when code changes.
- The
-
Run Streamlit Frontend: Open another new terminal window, activate your virtual environment, navigate to the project root, and run:
export PYTHONPATH=$PYTHONPATH:./ai_tutor_platform # For Linux/macOS # On Windows: set PYTHONPATH=%PYTHONPATH%;.\ai_tutor_platform streamlit run ai_tutor_platform/main.py --server.port 8501
-
Access the Application:
- Streamlit UI: Open your web browser and navigate to
http://localhost:8501 - FastAPI Docs: Open your web browser and navigate to
http://localhost:8000/docs(for API documentation)
- Streamlit UI: Open your web browser and navigate to
Deploying this multi-service application involves separate considerations for each component on cloud platforms. We'll outline deployment to Render (for FastAPI & PostgreSQL) and Streamlit Community Cloud (for Streamlit frontend).
- Recommended: Render PostgreSQL (or other managed PostgreSQL services like ElephantSQL, Railway, Supabase).
- Sign up for Render.com.
- Create a new PostgreSQL database service on Render. Choose a free-tier instance for testing.
- Once provisioned, note the Internal Database URL (for other Render services) and External Connection String (psql) (for local
psqlaccess). - Initialize Database Schema: Use the External Connection String to connect to your Render PostgreSQL database via
psqlfrom your local machine and run all yourCREATE TABLEandCREATE INDEXSQL scripts once.
- Recommended: Render.com (as a Web Service).
- On Render, create a new Web Service.
- Connect to your GitHub repository.
- Root Directory: Set this to
.(assuming yourai_tutor_platformdirectory is at the root of your Git repo). - Runtime: Select
Python 3. - Build Command:
pip install -r requirements.txt- Note: If using PyTesseract for image OCR, you'll need the Tesseract OCR engine installed. Render's standard Python runtime does not include this. You might need to add a build step to install it if allowed, or consider using a
Dockerfilefor more control over system dependencies.
- Note: If using PyTesseract for image OCR, you'll need the Tesseract OCR engine installed. Render's standard Python runtime does not include this. You might need to add a build step to install it if allowed, or consider using a
- Start Command:
export PYTHONPATH=$PYTHONPATH:./ai_tutor_platform && uvicorn ai_tutor_platform.main_api:app --host 0.0.0.0 --port $PORT
- Environment Variables:
GROQ_API_KEY: Your Groq API key (from Groq Console).DATABASE_URL: The Internal Database URL of your deployed Render PostgreSQL database.SECRET_KEY: A long, random, and securely generated string for JWT token signing.
- Recommended: Streamlit Community Cloud (
share.streamlit.io).-
Your Streamlit app's code (
ai_tutor_platform/main.py) must be in a public GitHub repository. -
.streamlit/secrets.toml: Create a.streamlitdirectory in your repository root and addsecrets.toml. This file is private to Streamlit Cloud and should contain your sensitive keys:# .streamlit/secrets.toml # Groq API Key for LLM access (if Streamlit still makes direct LLM calls or passes it) GROQ_API_KEY = "sk_your_real_groq_api_key_from_groq" # Streamlit secret for session state management (must be long and random) STREAMLIT_SECRET_KEY = "your_long_random_string_for_streamlit_session_state" # Public URL of your deployed FastAPI backend on Render FASTAPI_URL = "https://your-deployed-fastapi-app-name.onrender.com"
-
Deploy: Go to Streamlit Community Cloud, click "New app", select your repository and the main file (
ai_tutor_platform/main.py), and deploy.
-