Skip to content

About

A rule-based AI chatbot built in Python with a Tkinter desktop GUI, login system, persistent chat history, and a built-in calculator — plus a terminal version and a Streamlit web app. Developed as part of the DecodeLabs AI Internship to demonstrate Python programming and foundational AI/control-flow concepts.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🤖 DecodeBot — Rule-Based AI Chatbot

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. 05_streamlit_web_app 04_chat_history 03_chat_conversation 02_empty_chat 01_login_screen

📌 Project Overview

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.

✨ Features

  • 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's ast module, never eval(), 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

🛠️ Technologies Used

  • Python 3
  • Tkinter (desktop GUI)
  • Streamlit (web GUI)
  • Standard library: re, random, datetime, difflib, ast, hashlib, json

📂 Project Structure

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.

🚀 Installation

  1. Download this folder.

  2. Install dependencies:

    pip install -r requirements.txt

    Tkinter ships with most Python installs. On minimal Linux systems, if import tkinter fails, install it with: sudo apt-get install python3-tk

▶️ How to Run

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).

📈 How It Works

  1. Input — read from the terminal, Tkinter chat box, or Streamlit chat.
  2. Sanitization — lowercased and stripped of extra whitespace.
  3. 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").
  4. Output — the matched intent's reply (some, like time/date, are computed dynamically).
  5. Persistence (desktop app only) — every message is appended to the logged-in user's history file.
  6. Loop — continues until an exit command (exit, quit, bye, etc.).

🔒 A Note on the Login System

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.

🎯 Future Improvements

  • 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

👩‍💻 Developed As Part Of

DecodeLabs AI Internship — Project 1: Rule-Based AI Chatbot

📄 License

Licensed under the MIT License — see LICENSE for details.

About

A rule-based AI chatbot built in Python with a Tkinter desktop GUI, login system, persistent chat history, and a built-in calculator — plus a terminal version and a Streamlit web app. Developed as part of the DecodeLabs AI Internship to demonstrate Python programming and foundational AI/control-flow concepts.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages