Production-ready chat experience powered by BlenderBot (facebook/blenderbot-400M-distill) on a Flask backend with a modern, responsive frontend.
- Flask API with
/chat, CORS, in-memory rate limiting, and per-client conversation memory (last 5 turns) - BlenderBot via Hugging Face Transformers with temperature control, max response length, bad-word filtering, and context truncation to 1024 tokens
- ChatGPT-like UI: message bubbles, typing indicator, timestamps, copy-to-clipboard, clear chat, dark/light mode toggle, responsive layout
- Safety & resilience: input length caps, graceful model-unavailable responses, basic content filtering, and request throttling
- Install Python 3.10+
- Create and activate a venv (PowerShell):
python -m venv .venv; .venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Run the app:
Visit http://localhost:5000
python app.py
POST /chat- Body:
{ "message": "...", "client_id": "optional", "reset": false, "temperature": 0.0-1.5 } - Responses:
{ "response": "..." }on success, or{ "error": "..." }with status codes 4xx/5xx
- Body:
GET /- Serves the chat UI
GET /favicon.ico- Empty 204 to avoid 404 noise
MODEL_NAME(defaultfacebook/blenderbot-400M-distill)MAX_HISTORY_PAIRS(default 5)MAX_CONTEXT_TOKENS(default 1024)MAX_NEW_TOKENS(default 150)TEMPERATURE(default 0.8) — UI slider can override per requestTOP_P(default 0.9)RATE_LIMIT_MAX(default 10 requests)RATE_LIMIT_WINDOW(default 60 seconds)BAD_WORDScomma-separated list for filteringMAX_MESSAGE_CHARS(default 2000)
- Auto-scroll, Enter-to-send, copy-to-clipboard on AI replies
- Typing indicator while the backend generates
- Theme persistence (dark/light) via localStorage
- Client ID persistence with crypto UUID fallback for older browsers
- First run downloads the BlenderBot model (allow time/disk).
- Rate limiting and history are in-memory; they reset on restart.
- Clear Chat requests both reset the UI and ask the backend to drop history for that client.
- Basic bad-word masking in both user input and model output
- Input length clamp (
MAX_MESSAGE_CHARS) and context truncation (MAX_CONTEXT_TOKENS) - CORS enabled for local development; tighten origins for production
MIT