Skip to content

Palks-Studio/flask_chatbot_advanced_2.0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

122 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Chatbot conversation interface β€” example of a local Flask chatbot in use

πŸ‡¬πŸ‡§ English | πŸ‡«πŸ‡· FranΓ§ais

License OpenAI Optional Flask Offline First Flask Chatbot

Advanced Flask Chatbot β€” Version 2.0

This repository is a technical presentation and documentation repository.
It does not contain downloadable source code or production files.

A complete project to build your own Flask-based conversational assistant, ready to run:

  • locally (localhost)
  • on shared hosting such as o2switch (Passenger / cPanel)

No external database, no hidden dependencies. You can use it as-is, modify it, or integrate it into another website or API.

Flask Chatbot


Overview

This project provides a self-hosted conversational assistant built with Flask,
designed for developers and teams who want full control over their chatbot’s behavior and deployment.

The architecture prioritizes:

  • a local knowledge base (JSON) as the primary source
  • predictable behavior in professional environments
  • optional AI integration (OpenAI)
  • simple deployment without dependency on external SaaS platforms

Project Structure

flask_chatbot_advanced_2.0/
β”‚
β”œβ”€β”€ app.py                      β†’ Flask entry point (server + API routes)
β”œβ”€β”€ main.py                     β†’ Bot logic: responses (OpenAI + local JSON)
β”œβ”€β”€ storage.py                  β†’ SQLite-based conversation history (save & read)
β”‚
β”œβ”€β”€ passenger_wsgi.py           β†’ For hosting on o2switch / Passenger
β”œβ”€β”€ requirements.txt            β†’ Python dependencies (Flask, CORS, SQLite, OpenAI...)
β”œβ”€β”€ .env.example                β†’ Template for the user (β€œfill in your API key here”)
β”‚                                 # ⚠ The .env file is NOT included (user must create it to use OpenAI)
β”‚                                 # ⚠ The data.db file is not provided (created automatically on first run)
β”‚
β”œβ”€β”€ Dockerfile                  β†’ Dockerfile β†’ (optional) Docker container
β”œβ”€β”€ docker-compose.yml          β†’ docker-compose.yml β†’ (optional) Simplified Docker launch
β”‚
β”œβ”€β”€ LICENSE.md                  β†’ Terms of use and legal framework
β”‚
β”œβ”€β”€ install.bat                 β†’ Windows installation script (pip install + launch)
β”œβ”€β”€ install.sh                  β†’ Linux/Mac script (chmod + pip install)
β”‚
β”œβ”€β”€ sample_data/
β”‚   └── sample_data.json        β†’ Local content database (FAQ, simple answers)
β”‚
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ index.html              β†’ User interface (chatbot frontend)
β”‚   └── widget.html             β†’ New floating interface
β”‚
β”œβ”€β”€ static/
β”‚   β”œβ”€β”€ widget.js               β†’ Script to open/close the floating widget
β”‚   └── widget.css              β†’ Style for the floating widget (button + mini-window)
β”‚
β”œβ”€β”€ logs/
β”‚   └── errors.log              β†’ Automatically created on error
β”‚
└── docs/
    β”œβ”€β”€ README_TECHNIQUE.md     β†’ Technical documentation and internal architecture
    β”œβ”€β”€ README.md               β†’ Main project documentation and guides
    β”œβ”€β”€ CUSTOMISATION.md        β†’ Bot customization (design, responses, OpenAI…)
    └── INSTALL.md              β†’ Complete user guide

Key Features

  • Compatible with o2switch / Passenger (shared hosting)
  • No database required (JSON-based operation)
  • Readable, well-commented and easily customizable code
  • CORS enabled: usable with websites or frontend interfaces
  • Integrated logging system: errors automatically recorded in /logs/

Typical Use Cases

This chatbot is designed for:

  • internal knowledge assistants
  • support or documentation automation
  • self-hosted AI assistants
  • internal tools requiring controlled responses
  • websites embedding a chatbot widget

The system can operate fully offline using a local knowledge base,
or optionally use OpenAI when extended responses are required.


Automatically Generated Files

When the chatbot is launched for the first time, some files are created automatically:

File Purpose
data.db SQLite database storing conversations (if ENABLE_PERSISTENCE=true)
logs/errors.log Created only when a server error occurs
.env Must be created from .env.example to enable OpenAI

Operating Modes

Mode Description Requires OpenAI Key
Local JSON (default) Responses generated from the local knowledge base No
OpenAI GPT (optional) Uses OpenAI API when a key is provided Yes

The mode is automatically selected depending on the presence of the OPENAI_API_KEY variable in .env.
No tokens are consumed if no key is provided.


Error Logs

The logs/ directory automatically records Flask server errors:

  • automatic creation of logs/errors.log when an error occurs
  • automatic creation of the logs/ directory if missing
  • recording of date, error message and full traceback

This system works:

  • in local mode
  • with or without OpenAI
  • in production (Passenger / shared hosting)

Palks Studio β€” Version 2.0 (Advanced Edition)
Compatible with Python 3.12+ and Flask 3.0+

Β© Palks Studio β€” see LICENSE.md

About

πŸ‡¬πŸ‡§ Production-ready Flask chatbot template β€” offline-first, optional OpenAI, clean API & UI πŸ‡«πŸ‡· Template Flask prΓͺt Γ  l’emploi β€” fonctionnement hors ligne, OpenAI optionnel, API et interface propres.

Topics

Resources

License

Stars

Watchers

Forks

Contributors