Skip to content

marait123/pdf_chatbot

Repository files navigation

PDF Chatbot

A FastAPI-based chatbot that allows users to upload PDFs and ask questions about their content using Google's Generative AI.

pdf_chat_image

Prerequisites

  • Python 3.12 or higher
  • pip (Python package installer)
  • A Google API key for Generative AI

Setup

  1. Clone the repository:
git clone <repository-url>
cd pdf_chatbot
  1. Create a virtual environment:
python -m venv venv
  1. Activate the virtual environment:

On Windows:

.\venv\Scripts\activate

On Unix or MacOS:

source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
    • Copy the .env.example file to .env:
cp .env.example .env
  • Edit the .env file and set your configuration values:
# Required
APP_GOOGLE_API_KEY=your_google_api_key_here

# Optional (defaults shown)
APP_LOG_LEVEL=INFO
APP_ML_BUCKET_NAME=genai
APP_ML_MODEL_MODEL_NAME=gemini-1.5-flash
APP_ML_MODEL_TEMPERATURE=0.0
APP_ML_MODEL_MAX_RETRIES=2
APP_ML_TRIMMER_MAX_TOKENS=65000
APP_ML_CHUNK_SIZE=1000
APP_ML_CHUNK_OVERLAP=200
  1. Create required directories:
mkdir -p uploads static templates faiss_index

Running the Application

  1. Development mode with auto-reload:
uvicorn main:app --reload --port 8000
  1. Production mode:
uvicorn main:app --host 0.0.0.0 --port 8000

Or using Python directly:

python main.py

The application will be available at http://localhost:8000

Docker Support

  1. Build the Docker image:
docker build -t pdf-chatbot .
  1. Run the container:
docker run -p 8000:8000 --env-file .env pdf-chatbot

Usage

  1. Open your browser and navigate to http://localhost:8000
  2. Upload a PDF document using the upload form
  3. Start chatting with the bot about the content of your PDF

Project Structure

pdf_chatbot/
├── main.py              # FastAPI application
├── config.py            # Configuration management
├── faiss_db.py         # Vector database handler
├── requirements.txt     # Python dependencies
├── .env                 # Environment variables
├── .env.example        # Example environment file
├── static/             # Static files
│   ├── css/
│   └── js/
├── templates/          # Jinja2 templates
├── uploads/           # PDF uploads directory
└── faiss_index/       # Vector database storage

License

AGPL-3.0 License

Copyright (C)

This program is free software: you can redistribute it and/or modify it under the terms of the Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Affero General Public License for more details.

You should have received a copy of the Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Additional Terms: If you modify this program and use it over a network, you must make the source code available to the users of the program through the same means as this program. This applies to any modifications you make to the program, and any derivative works you create, regardless of whether they are used commercially or non-commercially.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published