Skip to content

Apyhtml20/PaperBrain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PaperBrain β€” Your Intelligent Study Assistant

PaperBrain Logo

AI-powered learning platform with RAG, Quiz, Flashcards, Explain, Resume β€” and local n8n AI Agent automation.


🌐 Spacy Demo Live :

πŸ”— Hugging Face Space: [https://huggingface.co/spaces/ApyHTML19/PaperBrainAI]

n8n PaperBrain Workflow

---

✨ Features

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

πŸ—οΈ Architecture

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

πŸ”„ n8n AI Agent (Local)

n8n PaperBrain Workflow

PaperBrain includes a local n8n AI Agent powered by Ollama llama3.1 that orchestrates all learning tools automatically.

Workflow Architecture

[Input Postman / Frontend]
        ↓
  [AI Agent For RAG]  ←→  [Ollama - llama3.1]
        ↓
  β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚                                    β”‚
[Flashcards Tool]  [Explain Tool]  [RAG Tool]  [Resume Tool]  [Quiz Tool]
        ↓
[Output Frontend]

Tools disponibles dans l'agent

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

Setup n8n local

# 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

Import the workflow

  1. Open n8n at http://localhost:5678
  2. Go to Workflows β†’ Import
  3. Import n8n/workflows/PaperBrain.json
  4. Configure the Ollama node with your local URL: http://localhost:11434
  5. Publish the workflow

πŸš€ Tech Stack

Backend

Frontend

Local AI Automation

  • n8n β€” AI Agent workflow automation
  • Ollama β€” Local LLM runtime
  • llama3.1 β€” Local AI model

Deployment


βš™οΈ Local Setup

Prerequisites

  • Python 3.10+
  • Node.js 18+
  • Ollama (for n8n local AI)

1. Clone the repo

git clone https://github.com/ApyHtml20/PaperBrain.git
cd PaperBrain

2. Backend

cd backend
pip install -r requirements.txt

Create .env:

HF_TOKEN=your_huggingface_token
HF_MODEL=Qwen/Qwen2.5-72B-Instruct
SECRET_KEY=your_secret_key_here
uvicorn app.main:app --reload --port 8000

3. Frontend

cd frontend
npm install
npm run dev

4. n8n + Ollama

ollama pull llama3.1
n8n start

πŸ”Œ API Endpoints

Auth

Method Route Description
POST /api/auth/register Create new account
POST /api/auth/login Login and get JWT token

Learning (πŸ”’ Auth required)

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

Documents (πŸ”’ Auth required)

Method Route Description
GET /api/documents List your documents
POST /api/upload Upload PDF/TXT/DOCX
DELETE /api/documents/{filename} Delete a document

🐳 Docker / HF Spaces

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=...

πŸ” Security

  • Passwords hashed with SHA-256 + random salt
  • JWT tokens expire after 24 hours
  • All routes protected by auth middleware
  • Documents isolated by user_id in ChromaDB
  • Files stored in documents/{user_id}/

About

AI-powered study assistant with RAG, Quiz, Flashcards, Explain & more. Built with FastAPI, React, ChromaDB & n8n local AI Agent (Ollama llama3.1)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors