A simple, free, and beginner-friendly Python chatbot that reads PDF or text documents and answers questions using keyword matching. No AI models needed, completely free to use!
- PDF & Text Support: Reads both PDF files and plain text files
- Keyword-Based Matching: Uses intelligent keyword matching to find relevant answers (no AI API calls needed)
- Interactive Chat: Real-time conversation mode with source tracking
- Fast & Free: No API keys required, runs entirely on your computer
- Simple Architecture: Clean, easy-to-understand code with clear explanations
- Multiple Input Modes: Interactive mode, demo mode, or test mode
srm-insider-chatbot/
βββ src/
β βββ chatbot.py # Main chatbot class (SRMInsiderBot)
β βββ main.py # Interactive entry point
β βββ demo.py # Automated demo with test questions
β βββ demo_text_chatbot.py # Text file demo
β βββ test_interactive.py # Interactive testing mode
β βββ pdf_to_text_converter.py # Convert PDF to text utility
β βββ create_sample_pdf.py # Generate sample PDF for testing
β βββ __pycache__/ # Python cache folder
βββ pdfs/ # PDF/text file storage folder
β βββ SRM_Content.txt # Sample SRM Insider content
βββ docs/ # Documentation folder
βββ requirements.txt # Python dependencies
βββ setup_git.sh # Git setup script
βββ QUICKSTART.md # Quick start guide
βββ README.md # This file
- Python 3.8+
- No API keys or internet connection needed!
-
Clone the repository
git clone <your-repo-url> cd srm-insider-chatbot
-
Create a virtual environment (recommended)
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Add your content
- Place your SRM Insider PDF or TXT file in the
pdfs/folder - The chatbot will automatically detect and use it
- Place your SRM Insider PDF or TXT file in the
Start a conversation with the chatbot:
cd src
python main.pyThen type your questions. Type quit or exit to end the conversation.
Test the chatbot with 5 predefined questions:
cd src
python demo.pyTest with more sample questions:
cd src
python demo_text_chatbot.pyAnother interactive mode for testing:
cd src
python test_interactive.pyThe chatbot uses a keyword matching algorithm:
1. User asks a question
β
2. Extract keywords from the question
(remove small words like "the", "and", "what")
β
3. Search through PDF/text content
for sections containing those keywords
β
4. Score each section based on:
- Keyword matches in section headers (highest score)
- Keyword matches in body text (lower score)
- Exact phrase matching
β
5. Return the highest-scoring section as the answer
along with source page number
β
6. Display answer to user
The SRMInsiderBot class handles everything:
__init__(): Initialize the chatbot with a PDF/text file pathload_pdf(): Load and extract text from PDF or TXT filesfind_relevant_text(): Search for text matching user's questionanswer_question(): Generate an answer with source informationinteractive_chat(): Run an interactive conversation
Key Features:
- Supports both PDF and TXT files
- Splits content into pages/sections
- Scores sections by relevance
- Returns top matching result with page number
Starts the chatbot in interactive mode:
- Finds available PDF/TXT files in the
pdfs/folder - Lets user choose which file to load (if multiple exist)
- Starts interactive chat session
Tests chatbot with 5 required questions:
- What is SRM INSIDER?
- When did it start?
- Who is the founder of SRM INSIDER?
- What are the domains of SRM INSIDER?
- What is SRM Roomie?
Demonstrates chatbot with 7 sample questions about SRM Insider.
Another interactive mode for testing the chatbot.
Converts PDF files to plain text for easier processing.
Creates a sample PDF with SRM Insider information for testing.
# Question: "What is SRM Insider?"
# Extracted keywords: ["srm", "insider"]
# (removed: "what", "is")- Perfect header match: 1000 points
- Most keywords in header: 100-150 points
- Some keywords in header: 30-50 points
- Keywords in body text: 1-2 points each
- Scores all content sections
- Returns section with highest score
- If no match found, says "couldn't find relevant information"
$ python main.py
==============================================================
Welcome to SRM Insider Chatbot
(Free & Simple - No AI Models!)
==============================================================
Loading text file: ../pdfs/SRM_Content.txt
β Loaded 5 sections from text file
β Total text length: 2500 characters
============================================================
SRM Insider Chatbot - Interactive Mode
============================================================
Type 'quit' or 'exit' to end the conversation
You: What is SRM Insider?
Bot: SRM Insider is a premier community platform...
Source pages: 1
You: Who founded it?
Bot: SRM Insider was founded by a group of visionary students...
Source pages: 1
You: quit
Bot: Goodbye! Thank you for using SRM Insider Chatbot.- PyPDF2: PDF text extraction
- Python 3.8+: Programming language
- Standard Library: File I/O, string processing
- Free Forever: No API costs, no subscriptions
- No Internet Needed: Works completely offline
- Privacy: Your data never leaves your computer
- Simple: Easy to understand and modify
- Fast: Instant responses without waiting for AI
- Beginner-Friendly: Well-commented code with clear logic
Each line of code has been written with simplicity in mind:
- Clear variable names
- Detailed comments
- Logical structure
- Type hints for clarity
For a detailed line-by-line explanation of the code, see the documentation or ask for specific file explanations.
- Place your PDF or TXT file in the
pdfs/folder - Run
python main.pyfrom thesrc/folder - Start asking questions!
- Type
quitto exit
For issues or questions:
- Check the QUICKSTART.md file
- Review the code comments in the src/ folder
- Test with the demo.py file first
This project is open source and free to use!