Sign inSign up

adityabhatt3010/ai-chatbot

By adityabhatt3010

β€’Updated over 1 year ago

Offline PDF-based AI chatbot using Ollama + FAISS + LangChain with Streamlit UI and Docker support

Image
Machine learning & AI
1

332

adityabhatt3010/ai-chatbot repository overview

⁠🌐 Universal Offline AI Chatbot

⁠Build your own domain-specific chatbot β€” offline, modular, and blazing fast.

Python LangChain Docker Offline

The Universal Offline AI Chatbot is a privacy-respecting, offline-ready assistant that can chat over any set of PDFs. It’s ideal for legal, cybersecurity, academic, enterprise, or technical domains.

It uses a locally hosted LLM (mistral:instruct via Ollama⁠) and semantic search powered by HuggingFace embeddings and FAISS. You get fast, accurate responses, without sending anything to the cloud.


⁠✨ Highlights

  • πŸ” Fully offline-capable with local LLM (via Ollama)
  • πŸ“„ Works out-of-the-box with your PDFs
  • 🧠 Semantic vector search using all-MiniLM-L6-v2
  • ⚑️ Fast and responsive using FAISS backend
  • 🧩 Modular, extendable architecture (Streamlit frontend + CLI)
  • 🐳 Docker-ready for deployment
  • πŸ“Έ UI Preview with screenshots
  • βœ… Built-in CI/CD check via GitHub Actions
  • 🎯 Fully reproducible setup via PowerShell script or Docker

⁠🧱 Tech Stack

LayerStack
LLMmistral:instruct via Ollama
Embeddingsall-MiniLM-L6-v2 via SentenceTransformers
Vector StoreFAISS (in-memory + disk)
FrameworkLangChain (v0.2+)
LanguagePython 3.11+
UIStreamlit
ContainerDocker
CI/CDGitHub Actions (.github/workflows/python.yml)

⚠️ HuggingFace Token is required to fetch the embedding model once. It's cached locally afterward.

Example .env:

HF_TOKEN=your_huggingface_token_here

β πŸ’‘ Use Cases

Chatbot TypeAdd These PDFs
πŸ‘¨β€βš–οΈ LawyerBotLegal, Constitution, HR documents
🧬 ResearchBotWhitepapers, scientific papers
πŸ›‘οΈ CyberSecBotSOC2, GDPR, ISO27001, NIST docs
πŸ“š EdTechBotNotes, textbooks, question banks
πŸ§‘β€πŸ’Ό HR/CompanyBotSOPs, onboarding docs, HR policies

β πŸ“ Project Structure

Universal-Offline-AI-Chatbot/
β”‚
β”œβ”€β”€ data/                   # Place your PDF documents here
β”‚   └── Try.pdf
β”‚
β”œβ”€β”€ Screenshots/           # UI snapshots
β”‚   β”œβ”€β”€ Loading_Screen.png
β”‚   └── Running_the_Model.png
β”‚
β”œβ”€β”€ src/                   # Modular source code
β”‚   β”œβ”€β”€ chunker.py
β”‚   β”œβ”€β”€ config.py
β”‚   β”œβ”€β”€ embedding.py
β”‚   β”œβ”€β”€ loader.py
β”‚   β”œβ”€β”€ model_loader.py
β”‚   β”œβ”€β”€ prompts.py
β”‚   β”œβ”€β”€ qa_chain.py
β”‚   β”œβ”€β”€ utils.py
β”‚   └── vectorstore.py
β”‚
β”œβ”€β”€ vectorstore/           # Local FAISS vector index
β”‚   └── db_faiss/
β”‚
β”œβ”€β”€ Bot.py                 # CLI script
β”œβ”€β”€ Bot.ipynb              # Jupyter notebook version
β”œβ”€β”€ main.py                # Entry-point (optional)
β”œβ”€β”€ streamlit_app.py       # Frontend UI (Streamlit)
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ setup.ps1              # PowerShell setup script
β”œβ”€β”€ Dockerfile             # Docker image definition
β”œβ”€β”€ .dockerignore
β”œβ”€β”€ .env                   # Contains HF_TOKEN
β”œβ”€β”€ README.md
└── LICENSE

⁠🧰 Setup Instructions

⁠πŸ–₯️ One-Click Setup (Windows Only)
.\setup.ps1

This will:

  • Create virtual env
  • Install dependencies
  • Pull Mistral via Ollama
  • Ask for Hugging Face token
  • Build Docker image

β πŸ›  Manual Setup
  1. Install Python Requirements
pip install -r requirements.txt
  1. Install & Pull Ollama Model
ollama pull mistral:instruct
  1. Set HuggingFace Token (First Time Only)
export HUGGINGFACEHUB_API_TOKEN=your_token      # macOS/Linux
set HUGGINGFACEHUB_API_TOKEN=your_token         # Windows CMD
  1. Run the CLI Bot
python Bot.py

⁠🌐 Run with Streamlit Frontend

streamlit run streamlit_app.py

⁠🐳 Docker Support

⁠Prerequisites
  • Docker installed & running
  • .env file containing HF_TOKEN (Hugging Face token)

β πŸ› οΈ Docker Build & Run

To build and run the chatbot using Docker, follow these steps:

  1. Build the Docker image:

    docker build -t ai-chatbot .
    
  2. Run the container (with volume mount and token):

    docker run -p 8501:8501 --env-file .env -v ${PWD}/data:/app/data ai-chatbot
    

    This will:

    • Map the container's port 8501 to local 8501
    • Use your local .env for HF_TOKEN
    • Mount the data/ folder into the container for access to PDFs

Access the chatbot at http://localhost:8501⁠


Let me know if you want the actual screenshot file names changed or if you’d like a quick CLI script to generate and store those screenshots automatically during your next run.


β πŸ”„ Using Your Own PDFs

# Replace default file(s)
mv your_files/*.pdf ./data/

# Re-run the bot or restart Streamlit
python Bot.py

Automatically re-indexes your new documents using FAISS.


⁠πŸ§ͺ Sample Interaction

🧠 You: What does Article 21 state?

πŸ€– Bot: Article 21 of the Indian Constitution guarantees the protection of life and personal liberty...

β πŸ§‘β€πŸ’» Author

Aditya Bhatt
Cybersecurity Specialist | VAPT Expert | OSS Contributor
GitHub⁠ | Medium⁠


Tag summary

Content type

Image

Digest

sha256:72941a9bb…

Size

3.3 GB

Last updated

over 1 year ago

docker pull adityabhatt3010/ai-chatbot