A Streamlit-based application that allows users to upload PDF documents and interact with their content using natural language queries. The app uses OpenAI's GPT-4 model and FAISS vector storage for efficient document retrieval and question answering.
- PDF document upload and processing
- Natural language querying of PDF content
- Conversation memory for context-aware responses
- Response caching for improved performance
- Cost estimation for embeddings and queries
- Clear chat history functionality
- Vector store persistence for faster subsequent loads
- Python 3.8 or higher
- OpenAI API key
- Clone the repository:
git clone https://github.com/rajat343/multiple_pdf_qa.git
cd multiple_pdf_qa- Create and activate a virtual environment (recommended):
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate- Install the required packages:
pip install -r requirements.txt- Create a
.envfile in the project root directory and add your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
- Start the Streamlit app:
streamlit run app.py-
Open your web browser and navigate to the URL shown in the terminal (typically
http://localhost:8501). -
Upload one or more PDF documents using the file uploader.
-
Start asking questions about the content of your PDFs in the chat interface.
pdf-chat-assistant/
├── app.py # Main application file
├── requirements.txt # Python dependencies
├── .env # Environment variables
├── uploaded_pdfs/ # Directory for stored PDFs
└── embeddings/ # Directory for stored vector embeddings
- PDFs are processed once and stored locally
- Document embeddings are cached for faster subsequent loads
- Multiple PDFs can be processed simultaneously
- Maintains conversation history for context-aware responses
- Allows clearing of chat history
- Caches question-answer pairs for improved performance
- Displays estimated costs for embeddings generation
- Shows per-query costs for API usage
- Uses efficient retrieval methods to minimize API calls
The application uses:
langchainfor document processing and chat chain managementFAISSfor efficient vector similarity searchOpenAI's GPT-4for generating responsesStreamlitfor the web interface- Document hashing for efficient storage and retrieval
- PDF processing may take longer for large documents
- API costs can accumulate with heavy usage
- Requires stable internet connection for API calls
- Maximum token limit applies based on GPT-4 model constraints
The application uses OpenAI's API which has associated costs:
- Embedding generation: $0.0001 per 1K tokens
- Query processing:
- Input: $0.0015 per 1K tokens
- Output: $0.002 per 1K tokens
Feel free to submit issues, fork the repository, and create pull requests for any improvements.