A Flask-based AI chatbot web application with a modern, responsive frontend, chat history, FAQ support, and OpenAI integration.
- Interactive chat interface with real-time messages
- FAQ matching for common user questions
- Persistent user chat history saved in a local SQLite database
- Session-based user tracking through cookies
- REST API endpoints for chat, history, and TTS integration
- Styled single-page frontend with history, stats, and settings panels
- Python 3.x
- Flask
- OpenAI API
- HTML/CSS/JavaScript frontend
- SQLite for local history storage
- Python 3.10+ installed
pippackage manager- OpenAI API key
- Clone the repository:
git clone https://github.com/<your-username>/<repo-name>.git
cd chatbot- Install dependencies:
pip install -r requirements.txtCreate a .env file in the project root with the following values:
OPENAI_API_KEY=your_openai_api_key
SECRET_KEY=your-secret-key
FLASK_ENV=development
FLASK_DEBUG=True
FLASK_HOST=127.0.0.1
FLASK_PORT=5000
DATABASE_PATH=chat_history.dbNotes:
OPENAI_API_KEYis required for chat responses when no FAQ match is found.DATABASE_PATHdefaults tochat_history.dbif not set.
python app.pyOpen your browser at:
http://127.0.0.1:5000/
POST /api/chat- Send a chat message and receive a responseGET /api/history- Retrieve the current user's chat historyDELETE /api/history/clear- Clear the current user's chat historyGET /api/history/stats- Retrieve usage statistics for the current userPOST /api/tts- Placeholder TTS endpoint for future integration
app/- Flask application packageapi/- Blueprint routes for chat, history, TTS, and health checksmodels/- Database models and persistence logicservices/- Chat processing, FAQ matching, and context managementtemplates/- HTML templatesstatic/- Frontend assets (CSS, JS)utils/- Session and input validation helpers
app.py- Application entry pointconfig.py- Environment-based configurationrequirements.txt- Python dependencies for developmentrequirements-prod.txt- Production dependency listDockerfile- Container build instructionsdocker-compose.yml- Service definition for local deploymentProcfile- Deployment process entry for platforms like Herokuruntime.txt- Python runtime version for platform deploymentwsgi.py- WSGI application entrypoint for production serverstests/- Automated test suite
- The app currently includes a placeholder TTS route; you can extend it with any speech service.
- Frontend assets are served from
app/templates/staticvia Flask's static file routing.
This project is available under the terms of the LICENSE file.