https://github.com/testpress/langchain-pdf-qa
https://github.com/testpress/langchain-pdf-qa
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/testpress/langchain-pdf-qa
- Owner: testpress
- Created: 2025-05-13T04:59:10.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-08T07:17:43.000Z (9 months ago)
- Last Synced: 2025-07-08T08:30:47.264Z (9 months ago)
- Language: Python
- Size: 332 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ LangChain PDF Q&A
Ask questions from any PDF using OpenAI + LangChain + Chroma.
This project lets you upload a PDF and ask natural language questions about its content. It uses:
- [LangChain](https://github.com/langchain-ai/langchain)
- [OpenAI API](https://platform.openai.com/)
- [Chroma Vector Store](https://www.trychroma.com/)
---
## ๐ง Setup
### 1. Clone the repo
```bash
git clone https://github.com/yourname/langchain-pdf-qa.git
cd langchain-pdf-qa
```
### 2. Install uv (if not already installed)
```bash
curl -Ls https://astral.sh/uv/install.sh | sh
```
### 3. Install dependencies
```bash
uv sync
```
### 3. Add your OpenAI API key
Create a `.env` file based on the example:
```bash
cp .env.example .env
```
Then edit `.env` and replace with your API key.
---
## โถ๏ธ Run the Q\&A CLI
```bash
uv run python ask_pdf.py
```
Place a PDF file (e.g., `example.pdf`) in the root and run the script. Youโll be prompted to ask questions like:
* "What is this document about?"
* "Who is the author?"
* "Summarize the key findings."
Type `exit` to quit.
---
## ๐งช Example
```text
Ask a question (or type 'exit'): What is the main purpose of this document?
Answer: This document provides an overview of ...
```
---
## ๐ Project Structure
```
.
โโโ ask_pdf.py
โโโ example.pdf # Your PDF file (not committed)
โโโ .env # Your API key (not committed)
โโโ .env.example
โโโ pyproject.toml
โโโ README.md
โโโ .gitignore
```
---
## ๐ก๏ธ Note
Do not commit your `.env` file or PDF files to GitHub. Use `.gitignore` to keep them private.
---
## ๐ก Ideas for Extension
* Add a Streamlit or Flask UI
* Use FAISS or Pinecone as vector store
* Deploy to Hugging Face Spaces or Render
---
## ๐ ๏ธ Development with uv
This project uses [uv](https://github.com/astral-sh/uv) for dependency management and Python environment handling.
### Common uv commands:
```bash
# Install dependencies
uv sync
# Run a script
uv run python ask_pdf.py
# Add a new dependency
uv pip install package-name
# Remove a dependency
uv pip uninstall package-name
# Update dependencies
uv sync --upgrade
# Run tests
uv run python -m pytest
# Activate the virtual environment (if needed)
source .venv/bin/activate
```
### Why uv?
- **Fast**: Much faster than pip and Poetry
- **Reliable**: Better dependency resolution
- **Simple**: Single tool for environment management, dependency installation, and running scripts
- **Modern**: Built for Python 3.13+ with modern tooling
---
## ๐งโ๐ป License
MIT โ free to use and modify.