How mhtbtanvir/plugbot works
Project type and purpose
• This is a full-stack, plugin-style chatbot system consisting of:
• A Python/Flask-based backend (app.py) exposing a REST API for chat interactions.
• An intent-classification model (PyTorch) with training scripts (train.py) and utilities (nltk_utils.py).
• A fallback conversational layer using Hugging Face’s DialoGPT-medium.
• Two frontends: a built-in “static” Flask templates/UI and a standalone-frontend directory with its own HTML/CSS/JS.
• Purpose: Provide an embeddable chatbot engine that first attempts intent matching, then falls back to a generative model.
File structure
• Top-level files:
• app.py – Flask server entrypoint, loads model/data, defines chat endpoints.
• chat.py – CLI for interactive chat on the command line.
• train.py – Script to train/update the intent classifier.
• model.py & nltk_utils.py – Model definition and NLP utilities.
• intents.json & data.pth – Core data: intent definitions and trained weights.
• Directories:
• static & templates – Flask’s default folder structure for built-in frontend assets and Jinja HTML templates.
• standalone-frontend – A self-contained frontend (vanilla JS / HTML / CSS) that can call the same API endpoints externally.
README for additional insights
• Confirms Flask + PyTorch + NLTK stack.
• Two modes: training (train.py) and serving (app.py).
• Fallback logic: use HF DialoGPT if intent confidence is low.
• Designed to be easily “plugged” into any frontend framework.
a. Main components:
• Frontend Layer
– “Built-in” Flask UI (templates & static/)
– Standalone frontend (HTML/CSS/JS)
• Backend Layer (Flask API)
– HTTP server (app.py)
– Intent classifier sub-module (model.py + nltk_utils.py + data.pth + intents.json)
– Fallback service adapter (DialoGPT Medium via Hugging Face API)
• Persistence Layer
– intents.json (configuration store)
– data.pth (model weights)
• Training Pipeline
– train.py reading intents.json, producing data.pth
• External Service
– Hugging Face DialoGPT-medium API
b. Relationships and data flow:
1. User interacts with a frontend → sends HTTP request to Flask API (/chat endpoint).
2. Flask API loads/uses the intent classifier:
• If confidence ≥ threshold → returns intent-based response.
• Otherwise → routes query to DialoGPT via external HTTP call, returns generative response.
3. train.py reads intents.json → pre-processes with nltk_utils → trains a PyTorch model → writes data.pth.
4. On server startup, app.py loads data.pth & intents.json into memory.
c. Architectural patterns/design principles:
• Layered architecture: UI → API → Model → External Service.
• Separation of concerns: training pipeline separated from serving pipeline.
• Fallback chain of responsibility: intent handler first, then generative adapter.
d. Key technologies/frameworks:
• Flask (web server/API)
• PyTorch (model training & inference)
• NLTK (tokenization, bag-of-words)
• Hugging Face API (DialoGPT-medium)
• Vanilla JS / HTML / CSS (frontend)