Skip to content
jostan30Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

📄 PDF Q&A Chatbot (FastAPI + Mistral + Next.js)

A lightweight AI system that lets you upload PDF files and ask questions about them in natural language using Mistral via OpenRouter API.

Screencast.from.2025-07-31.09-41-12.webm

🔧 Tech Stack

  • Backend: FastAPI, PyPDF2, SentenceTransformers, ChromaDB, OpenRouter (Mistral)
  • Frontend: Next.js + Tailwind + Lucide Icons
  • LLM: Mistral (via OpenRouter)
  • Embedding Model: all-MiniLM-L6-v2 (via SentenceTransformers)

Overview

Screenshot 2025-08-28 142630

🧠 Features

  • 📤 Upload PDF
  • ✂️ Extract and chunk text
  • 🧠 Generate vector embeddings and store in ChromaDB
  • 💬 Ask natural language questions
  • 🤖 Answer generated using Mistral LLM with relevant chunks
  • 🗑️ Clear/reset vector DB anytime

🚀 Backend (FastAPI)

Install dependencies:

pip install fastapi uvicorn python-dotenv requests PyPDF2 \
            sentence-transformers chromadb

Create .env file:

OPENROUTER_API_KEY=your_openrouter_key_here

Run server:

uvicorn main:app --reload

API Endpoints:

  • POST /upload_pdf/ → Upload and process PDF
  • POST /ask/ → Ask a question using Mistral
  • POST /reset_all_db/ → Reset vector store

💻 Frontend (Next.js UI)

Create app:

npx create-next-app@latest pdf-chat-ui
cd pdf-chat-ui
npm install lucide-react

Add ChatBox.tsx in /components/

Handles:

  • PDF Upload
  • API Calls
  • Chat history UI
  • Question box and reset logic

Run frontend:

npm run dev

🔄 Reset Vector DB

Use the following endpoint to delete all stored embeddings:

POST /reset_all_db/

📌 Notes

  • CORS middleware is enabled
  • Embeddings are generated once per upload
  • All conversations are stateless for now (no persistent memory)
  • ChromaDB stores are automatically created and queried

🧪 Sample Flow

# 1. Upload a PDF
curl -X POST http://localhost:8000/upload_pdf/ \
  -F "file=@example.pdf"

# 2. Ask a question
curl -X POST http://localhost:8000/ask/ \
  -F "query=What is the summary of this file?"

🔮 Future Improvements

  • 🔁 Add chat memory
  • 👥 Multi-user support
  • 🌍 Multi-language translation
  • 📊 PDF analytics and metrics

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages