Skip to content

Apyhtml20/PaperBrain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PaperBrain Logo

PaperBrain

Your AI-powered study assistant β€” chat, quiz, explain, summarize, and more.

PaperBrain screenshot


What is PaperBrain?

PaperBrain turns your documents into an interactive study session. Upload a PDF, ask questions about it, generate a quiz, get flashcards, or request a plain-English explanation β€” all in one place.

It runs on a FastAPI + React stack with Qwen 2.5-72B via HuggingFace for cloud inference, ChromaDB for document retrieval (RAG), and an optional local n8n AI Agent powered by Ollama for fully offline automation.


Features

Feature Description
πŸ’¬ General Chat Study assistant backed by Qwen 2.5-72B
πŸ“„ RAG Mode Ask questions directly about your uploaded documents
πŸ§ͺ Quiz Auto-generated multiple-choice quizzes on any topic
πŸƒ Flashcards Smart cards for active recall and memorization
πŸ’‘ Explain Concept breakdowns at beginner / intermediate / advanced level
πŸ“ Summarize Auto-summarize any text or uploaded document
πŸ“ Document Manager Upload PDF, TXT, DOCX β€” indexed per user with isolation
πŸ‘€ Auth JWT-based register/login with per-user data separation
πŸ“Š Profile & Stats Quiz history, streaks, and progression tracking
πŸ”„ n8n AI Agent Local agent with Ollama (llama3.1 / Qwen 2.5) + 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
β”‚   β”‚   β”‚   └── 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       # 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/
β”‚       └── PaperBrain.json
└── docs/
    β”œβ”€β”€ logo.png
    └── n8n-workflow.png

Local Setup

Prerequisites

  • Python 3.10+
  • Node.js 18+
  • Ollama (only required for the n8n local agent)

1 β€” Clone the repository

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

2 β€” Backend

cd backend
pip install -r requirements.txt

Create a .env file:

HF_TOKEN=your_huggingface_token
HF_MODEL=Qwen/Qwen2.5-72B-Instruct
SECRET_KEY=your_secret_key_here

Start the server:

uvicorn app.main:app --reload --port 8000

3 β€” Frontend

cd frontend
npm install
npm run dev

4 β€” n8n + Ollama (optional)

# Install and start Ollama, then pull the model
ollama pull llama3.1

# Install and start n8n
npm install -g n8n
n8n start
# β†’ http://localhost:5678

Then in n8n:

  1. Go to Workflows β†’ Import
  2. Import n8n/workflows/PaperBrain.json
  3. Set the Ollama node URL to http://localhost:11434
  4. Click Publish

n8n AI Agent

n8n PaperBrain Workflow

The local n8n agent orchestrates all learning tools automatically using Ollama llama3.1 β€” no cloud required.

[Postman / Frontend]
        ↓
  [AI Agent (RAG)]  ←→  [Ollama β€” llama3.1]
        ↓
  β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚           β”‚           β”‚        β”‚       β”‚
[Flashcards] [Explain] [RAG] [Summarize] [Quiz]
        ↓
[Frontend Output]
Tool What it does
πŸƒ Flashcards Generate flashcards on any topic
πŸ’‘ Explain Explain a concept at any depth
πŸ“„ RAG Search your uploaded documents
πŸ“ Summarize Summarize topics automatically
πŸ§ͺ Quiz Generate multiple-choice questions

API Reference

Auth

Method Route Description
POST /api/auth/register Create a new account
POST /api/auth/login Log in and receive a JWT token

Learning (requires auth)

Method Route Description
POST /api/chat General AI chat
POST /api/rag-qa Chat with your documents
POST /api/quiz Generate an MCQ quiz
POST /api/flashcards Generate flashcards
POST /api/explain Explain a concept
POST /api/resume Summarize text

Documents (requires auth)

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

Deploying to Hugging Face 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"]

Add these under Settings β†’ Variables and secrets:

HF_TOKEN=...
HF_MODEL=Qwen/Qwen2.5-72B-Instruct
SECRET_KEY=...

Tech Stack

Backend β€” FastAPI Β· SQLite + SQLAlchemy Β· ChromaDB Β· HuggingFace InferenceClient Β· python-jose Β· pdfplumber Β· python-docx

Frontend β€” React 18 Β· Vite

Local AI β€” n8n Β· Ollama Β· llama3.1

Deployment β€” Hugging Face Spaces (Docker)


Security

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

Live Demo

πŸ”— huggingface.co/spaces/ApyHTML19/PaperBrainAI

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