Spaces:
Sleeping
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) | |
| 1. Create a Supabase project at https://supabase.com | |
| 2. Go to Project Settings β Database β Connection string (URI) | |
| 3. Enable pgvector: Go to SQL Editor and run: | |
| ```sql | |
| CREATE EXTENSION vector; | |
| ``` | |
| 4. Add your Supabase connection string as `DATABASE_URL` secret in HF Spaces | |
| ### Option 2: Use Render PostgreSQL | |
| 1. Create a PostgreSQL database on Render.com | |
| 2. Connect and enable pgvector: | |
| ```sql | |
| CREATE EXTENSION vector; | |
| ``` | |
| 3. 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: | |
| ```bash | |
| # 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 | |
| ```bash | |
| # 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. | |