A deterministic, dictionary-driven chatbot built in Python, developed as
part of the DecodeLabs AI Internship — Project 1. Ships with three
interfaces — terminal, desktop (Tkinter), and web (Streamlit) — all powered
by the exact same rule engine, so behavior never drifts between them.

DecodeBot answers user questions using explicit, hard-coded rules — no machine learning, no external API calls. It's the "logic engine" foundation that comes before generative AI: every response can be traced from input → logic → output with zero hallucination risk.
- Continuous conversation loop with a clean exit command
- Input sanitization (case-insensitive, whitespace-trimmed)
- 20+ intents: greetings, small talk, bot info, jokes, time/date, mood detection, and more
- Two-tier intent matching: exact trigger phrases first, then bag-of-words keyword scoring for paraphrased questions
- Typo tolerance via fuzzy matching (suggests the closest known phrase)
- Built-in calculator (
"calculate 12*4") — parsed safely via Python'sastmodule, nevereval(), so it can't execute arbitrary code - Login system — username/password accounts, salted SHA-256 password hashes, plus a ready-to-use demo account
- Persistent chat history — saved per-user to disk; viewable and clearable from the GUI
- Lightweight session memory (remembers the user's name, message count)
- Fallback response for anything outside its rule set
- Three interfaces: terminal script, Tkinter desktop app, Streamlit web app
- Python 3
- Tkinter (desktop GUI)
- Streamlit (web GUI)
- Standard library:
re,random,datetime,difflib,ast,hashlib,json
decodebot/
│
├── chatbot_logic.py # Core rule engine (intents, matching, replies, calc)
├── calculator.py # Safe AST-based arithmetic evaluator
├── login.py # Username/password auth (salted hashes)
├── file_manager.py # Per-user persistent chat history
├── chatbot.py # Terminal interface
├── gui.py # Tkinter desktop interface (login -> chat)
├── main.py # Entry point for the desktop app
├── app.py # Streamlit web interface
├── requirements.txt
├── README.md
└── LICENSE
users.json and the history/ folder are created automatically the first
time you run the app — they aren't shipped with the project.
-
Download this folder.
-
Install dependencies:
pip install -r requirements.txt
Tkinter ships with most Python installs. On minimal Linux systems, if
import tkinterfails, install it with:sudo apt-get install python3-tk
| Interface | Command |
|---|---|
| Terminal | python chatbot.py |
| Desktop app (GUI, login, history) | python main.py |
| Web app (Streamlit) | streamlit run app.py |
Desktop app demo account: username demo, password demo123
(auto-created on first run — or click "Create Account" to make your own).
- Input — read from the terminal, Tkinter chat box, or Streamlit chat.
- Sanitization — lowercased and stripped of extra whitespace.
- Matching
- Tier 0: is this a plain math expression? → routed to the calculator.
- Tier 1: exact trigger phrases (e.g.
"how are you"). - Tier 2: bag-of-words keyword overlap scoring for paraphrased input.
- Tier 3: fuzzy typo suggestion (e.g.
"helo"→"hello").
- Output — the matched intent's reply (some, like time/date, are computed dynamically).
- Persistence (desktop app only) — every message is appended to the logged-in user's history file.
- Loop — continues until an exit command (
exit,quit,bye, etc.).
This is a learning-project login demo, not production-grade auth: passwords are salted and hashed (never stored in plain text), but there's no rate limiting, session expiry, or HTTPS transport involved. Good enough to demonstrate the concept — not something to reuse for a real product without hardening it further.
- Add multi-turn conversational context
- Hybrid mode: fall back to an LLM when no rule matches
- Sync chat history across devices (currently local file storage only)
- Deploy the Streamlit version online via Streamlit Community Cloud
DecodeLabs AI Internship — Project 1: Rule-Based AI Chatbot
Licensed under the MIT License — see LICENSE for details.