This is a Streamlit web application that allows you to upload PDF documents, create a vector database from their content, and then ask questions directly related to the PDF. It leverages Langchain for document processing and retrieval, and Ollama for running local large language models (LLMs) and generating embeddings.
-
PDF Upload: Easily upload your PDF documents.
-
Vector Database Creation: Automatically processes your PDF into text chunks and builds an in-memory vector database using FAISS for efficient similarity search.
-
Local LLM Integration: Connects to your local Ollama server to utilize various open-source LLMs for question answering.
-
Model Selection: Select from any Ollama model available on your system.
-
Temperature Control: Adjust the generation temperature of the LLM to control the randomness of the output.
-
Source Document Display: Shows the relevant text chunks from the PDF that were used to formulate the answer.
Before running this application, ensure you have the following installed and configured:
-
Python 3.8+: Download Python at https://www.python.org/
-
Ollama:
- Download and install Ollama from ollama.ai.
- Once installed, pull at least one LLM model (e.g., llama2, deepseek-r1, phi mistrel) using your terminal: ollama pull llama2
-
Ensure the Ollama server is running.
Follow these steps to set up and run the application:
-
Clone the Repository (or create the file): If you're provided with a repository, clone it. Otherwise, save the provided Python code (from the Canvas document) as app.py in a directory of your choice.
-
Create a Virtual Environment (Recommended): Navigate to your project directory in the terminal and create a virtual environment:
# This will create virtual envrionment python -m venv venv #Activate the Virtual Environment: # --> On Windows: .\venv\Scripts\activate # --> On macOS / Linux: source venv/bin/activate
-
Install Dependencies: Install all required Python libraries:
pip install -r requirments.txt
-
Start the Ollama Server: Ensure Ollama is running in the background on your system.
# To start ollama server you can use ollama serve -
Run the Streamlit Application: From your terminal, navigate to the directory containing app.py and execute:
streamlit run app.py
- This will open the application in your default web browser (usually at http://localhost:8501).
-
Ollama Server URL: If your Ollama server is not running on the default http://localhost:11434, update the URL in the sidebar.
-
Select Ollama Model: Choose your desired LLM model from the dropdown in the sidebar.
-
Adjust Temperature: Use the slider to set the model's temperature.
-
Upload PDF: Click the "Upload your PDF document" button and select a PDF file.
-
Ask Questions: Once the vector database is built, type your question in the "Enter your question:" text area and click "Get Answer".
-
Error : Could not connect to Ollama server...":
-
Make sure Ollama is installed and actively running on your system.
-
Verify the "Ollama Server URL" in the sidebar is correct.
-
Check your firewall settings if you suspect a blockage.
-
-
Error : "No Ollama models found...":
-
Ensure you have pulled at least one model (e.g., ollama pull llama2) using the Ollama CLI.
-
Confirm Ollama is running.
-
-
"Error creating embeddings or vector store..." / "Error getting answer...":
-
The selected Ollama model might not be fully downloaded or accessible. Try pulling the model again or selecting a different one.
-
Check the Ollama server logs for more detailed error messages.
-
-
Application is slow:
-
Processing very large PDFs can take time.
-
The performance depends heavily on your system's resources and the size/complexity of the chosen Ollama model.
-
- Author : Kuldeep Singh
- Email : shergillkuldeep@outlook.com
- License : MIT
- Manually select the embedding model before pdf upload.
- Manually select the LLM model before Question and Answer