Spaces:
Sleeping
title: LearnHub AI Platform
emoji: π
colorFrom: purple
colorTo: blue
sdk: docker
app_port: 7860
pinned: false
LearnHub - Phase 2 AI Learning Platform
Advanced AI-powered learning platform with multi-user support, course management, and RAG-based tutoring.
Features
β
User Authentication - JWT-based auth with student/instructor/admin roles
β
Course Management - Modules, lessons, quizzes, and progress tracking
β
AI Tutor - RAG-powered Q&A using PostgreSQL pgvector + Google Gemini
β
Smart Features - Auto-generate summaries, MCQs, and progressive hints
β
Forum - Discussion boards for students and instructors
β
Vector Search - pgvector for semantic search over course materials
Tech Stack
- Backend: FastAPI + SQLAlchemy + PostgreSQL
- Vector DB: pgvector extension for PostgreSQL
- AI: Google Gemini 2.5 Flash + LangChain
- Auth: JWT tokens with bcrypt password hashing
Deployment on HuggingFace Spaces
This Space requires a PostgreSQL database with pgvector extension.
Option 1: Use Supabase (Recommended)
- Create a Supabase project at https://supabase.com
- Go to Project Settings β Database β Connection string (URI)
- Enable pgvector: Go to SQL Editor and run:
CREATE EXTENSION vector; - Add your Supabase connection string as
DATABASE_URLsecret in HF Spaces
Option 2: Use Render PostgreSQL
- Create a PostgreSQL database on Render.com
- Connect and enable pgvector:
CREATE EXTENSION vector; - Use the external connection string as
DATABASE_URL
Required Secrets
Configure in Settings β Variables and secrets:
DATABASE_URL=postgresql+asyncpg://user:password@host:5432/database
GOOGLE_API_KEY=your_google_api_key
JWT_SECRET_KEY=your-super-secret-jwt-key
CORS_ORIGINS=https://your-frontend.vercel.app
Run Database Migrations
After deployment, you need to run Alembic migrations:
# Connect to your database and enable pgvector
CREATE EXTENSION IF NOT EXISTS vector;
# Or use the migration script in alembic/versions/
API Endpoints
| Endpoint | Description |
|---|---|
POST /auth/register |
Register new user |
POST /auth/login |
Login and get JWT token |
GET /courses |
List all courses |
POST /tutor/ask |
Ask AI tutor a question (RAG) |
POST /tutor/generate-mcq |
Generate MCQ questions |
POST /tutor/hint |
Get progressive hints |
GET /docs |
Interactive API documentation |
Local Development
# Setup
cd backend
pip install -r requirements.txt
# Configure .env
cp .env.example .env
# Edit .env with your credentials
# Run migrations
alembic upgrade head
# Start server
uvicorn app.main:app --reload --port 8001
Differences from Phase 1
| Feature | Phase 1 | Phase 2 |
|---|---|---|
| Database | SQLite | PostgreSQL |
| Vectors | Pinecone | pgvector (PostgreSQL) |
| Auth | None | JWT multi-user |
| Courses | No | Full course management |
| AI Features | Basic Q&A | Q&A + MCQ + Summaries + Hints |
| Users | Single | Multi-user with roles |
Note: This is the backend API only. For a full app experience, deploy the Next.js frontend separately and connect via CORS.