This NLP Chatbot Application is a web-based conversational agent built with Python, Flask, and natural language processing techniques. The chatbot provides an intuitive user interface for interactive conversations, responding to user queries using pattern matching and context-based response generation.
Live Demo: https://chatbot-app-d9i6.onrender.com/
Repository: https://github.com/Ismat-Samadov/chatbot_app
- Features
- Architecture
- Technology Stack
- Implementation Details
- Installation and Setup
- Usage Guide
- Code Structure
- Pattern Matching System
- Response Generation
- UI/UX Design
- Deployment
- Future Enhancements
- Lessons Learned
- Contributors
- License
- Real-time Conversation: Instant messaging interface with dynamic responses
- Pattern Recognition: Identifies user intents through regex pattern matching
- Context-based Responses: Generates appropriate replies based on identified topics
- Dark/Light Theme Toggle: User-customizable interface appearance
- Responsive Design: Fully functional across desktop and mobile devices
- Typing Indicators: Visual feedback when the chatbot is "thinking"
- Timestamp Display: Shows the time each message was sent
- Simple Deployment: Easy to deploy on cloud platforms like Render
The application follows a client-server architecture with the following components:
flowchart TD
A[User Interface] <--> B[Flask Web Server]
B <--> C[NLP Processing Engine]
subgraph "Frontend"
A
end
subgraph "Backend"
B
C
end
C --> D[(Pattern Database)]
C --> E[(Response Templates)]
sequenceDiagram
participant User
participant Frontend
participant Backend
participant NLP Engine
User->>Frontend: Enter message
Frontend->>Backend: Send HTTP POST request
Backend->>NLP Engine: Process message
NLP Engine->>Backend: Return appropriate response
Backend->>Frontend: Send JSON response
Frontend->>User: Display bot response
- HTML5/CSS3: Page structure and styling
- JavaScript (ES6+): Client-side interactivity
- Font Awesome: Icons for user interface elements
- Google Fonts (Poppins): Typography
- Python 3.x: Server-side programming
- Flask: Web framework
- Regular Expressions: Pattern matching for intent recognition
- Random module: Response variation for natural conversation
- JSON: Data exchange format
- Render: Cloud platform hosting
- Git/GitHub: Version control and source code management
- Gunicorn: WSGI HTTP Server for production
The chatbot employs a rule-based approach to natural language processing:
- Intent Recognition: Uses regular expressions to match user inputs with predefined patterns
- Response Selection: Chooses appropriate responses from categorized templates
- Contextual Analysis: Identifies specific keywords to provide topic-relevant replies
- Default Handling: Provides general responses when no specific pattern is matched
This approach provides a foundation for conversational interaction while remaining lightweight and efficient for web deployment.
- Python 3.7 or higher
- pip (Python package manager)
- Git (optional, for cloning the repository)
-
Clone the repository:
git clone https://github.com/Ismat-Samadov/chatbot_app.git cd chatbot_app -
Create and activate a virtual environment:
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python app.py
-
Open your browser and navigate to:
http://localhost:8080
- Open the chatbot application in your web browser
- The chatbot will greet you with a welcome message
- Type your message in the input field at the bottom
- Press Enter or click the send button to submit
- Greetings: "Hi", "Hello", "Hey there"
- Questions about the bot: "Who are you?", "What can you do?"
- Topic-specific queries: "Tell me about Python", "What's this course about?"
- Closing the conversation: "Goodbye", "Thanks", "Bye"
Click the moon/sun icon in the top-right corner to switch between light and dark themes.
The project follows a clear organization pattern:
chatbot_app/
│
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
├── .gitignore # Git ignore rules
├── LICENSE # MIT License
│
├── static/ # Static assets
│ ├── style.css # CSS styling
│ └── script.js # Client-side JavaScript
│
└── templates/ # HTML templates
└── index.html # Main page template
The chatbot uses regular expressions to identify user intents:
patterns = {
"greeting": r"(?i)^(hi|hello|hey|greetings|good (morning|afternoon|evening)).*",
"goodbye": r"(?i)^(bye|goodbye|see you|farewell|exit|quit).*",
"thanks": r"(?i)^(thanks|thank you|appreciate it|grateful).*",
"how_are_you": r"(?i)^(how are you|how('s| is) it going|what('s| is) up|how do you do).*",
"who_are_you": r"(?i)^(who are you|what are you|tell me about yourself|introduce yourself).*",
"capabilities": r"(?i)^(what can you do|what are your capabilities|help|functions|features).*"
}Key features of this system:
- Case insensitivity: Using
(?i)flags - Pattern alternatives: Pipe operator
|for multiple matching options - Grouping: Parentheses to organize complex patterns
- Beginning of string:
^anchor to match from the start - Wildcards:
.*to allow any text after the pattern
Responses are organized by intent categories:
responses = {
"greeting": ["Hello!", "Hi there!", "Greetings!", "Hey, how can I help?"],
"goodbye": ["Goodbye!", "See you later!", "Bye!", "Take care!"],
"thanks": ["You're welcome!", "Glad I could help!", "No problem!", "Anytime!"],
"how_are_you": ["I'm doing well, thanks for asking!", "I'm good! How about you?", "I'm fine, how can I help?"],
"who_are_you": ["I'm a simple chatbot built with Python and Flask.", "I'm your AI assistant, how can I help?"],
"capabilities": ["I can answer simple questions and have basic conversations.", "I'm a basic chatbot that can respond to various prompts."],
"default": ["I'm not sure I understand. Could you rephrase that?", "Interesting. Tell me more.", "I'm still learning. Could you elaborate?"]
}The process flow for generating responses:
flowchart TD
A[Receive User Message] --> B{Pattern Match?}
B -->|Yes| C[Select Response from Matched Intent]
B -->|No| D{Keyword Present?}
D -->|Yes| E[Select Relevant Contextual Response]
D -->|No| F[Select Default Response]
C --> G[Return Response to User]
E --> G
F --> G
The chatbot interface was designed with the following principles:
- Simplicity: Clean layout focusing on the conversation
- Familiarity: Chat interface patterns users recognize
- Accessibility: Clear typography and contrasting colors
- Responsiveness: Adaptable to different screen sizes
- Visual Feedback: Typing indicators and message animations
flowchart TD
A[User Interface] --> B{Theme Selection}
B -->|Light Theme| C[Light Background / Dark Text]
B -->|Dark Theme| D[Dark Background / Light Text]
C --> E[Blue Accent Colors]
D --> F[Purple Accent Colors]
- Desktop: 800px max-width container
- Tablet: 768px responsive adjustments
- Mobile: 480px further optimizations
The application is deployed on Render, a cloud platform that simplifies web service hosting.
- Repository Setup: Code pushed to GitHub repository
- Render Configuration:
- Connected to GitHub repository
- Set Python environment
- Specified build command:
pip install -r requirements.txt - Set start command:
gunicorn app:app
- Environment Configuration:
- Set PORT environment variable
- Deployment Trigger: Automatic deployment on main branch updates
flowchart LR
A[Local Development] -->|Git Push| B[GitHub Repository]
B -->|Webhook| C[Render Build Process]
C -->|Deploy| D[Render Web Service]
D -->|Serve| E[End Users]
The current implementation provides a foundation that can be extended in several ways:
- Extended vocabulary: Add more patterns and responses
- Session management: Remember conversation context
- User feedback system: Collect ratings on response quality
- Integration with transformer models: Implement Hugging Face transformers
- Multi-language support: Add capability for different languages
- Voice input/output: Add speech recognition and synthesis
- Machine learning pipeline: Train on conversation data
- API integrations: Connect to weather, news, or other services
- Personalization: Learn user preferences over time
- Pattern matching limitations: Simple regex patterns work for basic intents but struggle with complex queries
- Frontend-backend communication: Handling asynchronous requests properly
- Deployment considerations: Environment configuration for cloud platforms
- Scope definition: Starting with a minimal viable product
- Feature prioritization: Building core functionality first
- Documentation importance: Maintaining clear explanations of code functionality
- Ismat Samadov - Initial work and maintainer
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 Ismat-Samadov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.