AI-powered learning platform with RAG, Quiz, Flashcards, Explain, Resume — and local n8n AI Agent automation.
🔗 Hugging Face Space: [https://huggingface.co/spaces/ApyHTML19/PaperBrainAI]
---| Feature | Description |
|---|---|
| 💬 General Chat | AI-powered study assistant (Qwen 2.5-72B) |
| 📄 RAG Mode | Ask questions based on your uploaded documents |
| 🧪 Quiz | Auto-generated MCQ quizzes on any topic |
| 🃏 Flashcards | Smart flashcards for memorization |
| 💡 Explain | Concept explanations at beginner / intermediate / advanced level |
| 📝 Resume | Auto-summarize any text or document |
| 📁 Document Manager | Upload PDF, TXT, DOCX — indexed per user |
| 👤 Auth | JWT-based register/login with user isolation |
| 📊 Profile & Stats | Quiz history, streaks, progression tracking |
| 🔄 n8n AI Agent | Local AI Agent with Ollama llama3.1/Qwen 2.5 (Locally/Pre-trained Model on HuggingFace + 5 tools |
PaperBrain/
├── backend/ # FastAPI Python backend
│ ├── app/
│ │ ├── auth/
│ │ │ ├── jwt_handler.py # JWT token creation/decoding
│ │ │ └── middleware.py # get_current_user dependency
│ │ ├── db/
│ │ │ ├── database.py # SQLite + SQLAlchemy setup
│ │ │ ├── models.py # User, QuizResult, StudySession models
│ │ │ └── crud.py # DB operations
│ │ ├── tools/ # AI tool modules
│ │ ├── agent.py # Main AI dispatcher
│ │ ├── ingest.py # Document ingestion + chunking
│ │ ├── rag.py # ChromaDB vector store
│ │ ├── router_service.py # All API routes
│ │ ├── schemas.py # Pydantic request models
│ │ └── main.py # FastAPI app entry point
│ ├── Dockerfile
│ └── requirements.txt
├── frontend/ # React frontend
│ └── src/
│ └── pages/
│ ├── Chat.jsx
│ ├── Quiz.jsx
│ ├── Flashcards.jsx
│ ├── Documents.jsx
│ └── Profile.jsx
├── n8n/ # Local n8n AI Agent workflows
│ └── workflows/
│ └── PaperBrain.json
└── docs/
├── logo.png
└── n8n-workflow.png
PaperBrain includes a local n8n AI Agent powered by Ollama llama3.1 that orchestrates all learning tools automatically.
[Input Postman / Frontend]
↓
[AI Agent For RAG] ←→ [Ollama - llama3.1]
↓
┌─────┴──────────────────────────────┐
│ │
[Flashcards Tool] [Explain Tool] [RAG Tool] [Resume Tool] [Quiz Tool]
↓
[Output Frontend]
| Tool | Description |
|---|---|
| 🃏 Flashcards Tool | Generate flashcards on any topic |
| 💡 Explain Tool | Explain a concept at any level |
| 📄 RAG Tool | Search course documents for answers |
| 📝 Resume Tool | Summarize topics automatically |
| 🧪 Quiz Tool | Generate MCQ quiz questions |
# Install n8n
npm install -g n8n
# Start n8n
n8n start
# → Access at http://localhost:5678
# Install Ollama
# https://ollama.com/download
# Pull llama3.1
ollama pull llama3.1- Open n8n at
http://localhost:5678 - Go to Workflows → Import
- Import
n8n/workflows/PaperBrain.json - Configure the Ollama node with your local URL:
http://localhost:11434 - Publish the workflow
Backend
- FastAPI — REST API
- SQLite + SQLAlchemy — Database
- ChromaDB — Vector store for RAG
- HuggingFace InferenceClient — Cloud AI (Qwen2.5-72B)
- python-jose — JWT authentication
- pdfplumber + python-docx — Document parsing
Frontend
Local AI Automation
Deployment
- Hugging Face Spaces — Docker deployment
- Python 3.10+
- Node.js 18+
- Ollama (for n8n local AI)
git clone https://github.com/ApyHtml20/PaperBrain.git
cd PaperBraincd backend
pip install -r requirements.txtCreate .env:
HF_TOKEN=your_huggingface_token
HF_MODEL=Qwen/Qwen2.5-72B-Instruct
SECRET_KEY=your_secret_key_hereuvicorn app.main:app --reload --port 8000cd frontend
npm install
npm run devollama pull llama3.1
n8n start| Method | Route | Description |
|---|---|---|
| POST | /api/auth/register |
Create new account |
| POST | /api/auth/login |
Login and get JWT token |
| Method | Route | Description |
|---|---|---|
| POST | /api/chat |
General AI chat |
| POST | /api/rag-qa |
Chat with your documents |
| POST | /api/quiz |
Generate MCQ quiz |
| POST | /api/flashcards |
Generate flashcards |
| POST | /api/explain |
Explain a concept |
| POST | /api/resume |
Summarize text |
| Method | Route | Description |
|---|---|---|
| GET | /api/documents |
List your documents |
| POST | /api/upload |
Upload PDF/TXT/DOCX |
| DELETE | /api/documents/{filename} |
Delete a document |
FROM python:3.11-slim
WORKDIR /code
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]HF Spaces secrets (Settings → Variables and secrets):
HF_TOKEN=...
HF_MODEL=Qwen/Qwen2.5-72B-Instruct
SECRET_KEY=...
- Passwords hashed with SHA-256 + random salt
- JWT tokens expire after 24 hours
- All routes protected by auth middleware
- Documents isolated by
user_idin ChromaDB - Files stored in
documents/{user_id}/


