This project is a web-based AI assistant that allows you to upload a PDF document and ask questions about its content. It uses a Retrieval-Augmented Generation (RAG) pipeline powered by Google's Gemini Pro model and LangChain to provide intelligent and context-aware answers.
- Interactive UI: A clean and user-friendly interface for uploading files and chatting.
- PDF Upload: Supports uploading PDF documents via button click or drag-and-drop.
- Document Processing: Extracts text from the PDF, splits it into manageable chunks, and creates a searchable vector index.
- Conversational Q&A: Ask questions in natural language and receive answers generated by a powerful AI model based on the document's content.
- Powered by Gemini: Utilizes Google's
gemini-2.5-profor high-quality responses andembedding-001for text embeddings.
- Backend: Python, FastAPI
- AI/ML: LangChain, Google Generative AI (Gemini), FAISS (for vector storage)
- Frontend: HTML, CSS, JavaScript
- PDF Processing: PyPDF2
The application follows a Retrieval-Augmented Generation (RAG) architecture:
-
PDF Processing: When a user uploads a PDF, the backend extracts all text content.
-
Text Chunking: The extracted text is split into smaller, overlapping chunks to ensure semantic context is preserved.
-
Vector Embedding: Each text chunk is converted into a numerical vector representation (embedding) using Google's
models/embedding-001. -
Vector Store: These embeddings are stored in a local FAISS vector store, which allows for efficient similarity searches.
-
Question Answering:
- The question is converted into an embedding.
- The FAISS store is searched to find the text chunks with embeddings most similar to the question's embedding.
- These relevant chunks (the context) and the original question are passed to the Gemini Pro model via a carefully crafted prompt.
- The model generates a final, human-like answer based on the provided context.
- Python 3.9+
- A Google API Key with the "Generative Language API" enabled (available from Google AI Studio).
# Windows
python -m venv venv
venv\Scripts\activate
# macOS/Linux
python3 -m venv venv
source venv/bin/activateCreate a requirements.txt file with the following:
fastapi
uvicorn[standard]
python-dotenv
google-generativeai
langchain-google-genai
langchain
pypdf2
faiss-cpu
Install everything:
pip install -r requirements.txtCreate a .env file in the main project folder and add:
GOOGLE_API_KEY="PASTE_YOUR_SECRET_API_KEY_HERE"
uvicorn app:app --reloadThen open your browser and go to: http://127.0.0.1:8000 live demo : https://studyassistant-dzq4.onrender.com/
.
├── app.py # The heart of our backend server
├── templates/
│ └── index.html # The main (and only) HTML page
├── static/
│ ├── style.css # Makes everything look pretty
│ └── script.js # Powers all the interactive features
├── .env # Where your secret API key lives
├── requirements.txt # A list of the Python tools we need
└── README.md # You're reading it!