10000 GitHub - testpress/langchain-pdf-qa
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

testpress/langchain-pdf-qa

Repository files navigation

📄 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:


🔧 Setup

1. Clone the repo

git clone https://github.com/yourname/langchain-pdf-qa.git
cd langchain-pdf-qa

2. Install uv (if not already installed)

curl -Ls https://astral.sh/uv/install.sh | sh

3. Install dependencies

uv sync

3. Add your OpenAI API key

Create a .env file based on the example:

cp .env.example .env

Then edit .env and replace with your API key.


▶️ Run the Q&A CLI

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

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 for dependency management and Python environment handling.

Common uv commands:

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0