Skip to content

A collection of Python chatbots with basic, enhanced, and NLP features

License

Notifications You must be signed in to change notification settings

praytyushpande/python-chatbot-collection-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python Chatbot Collection πŸ€–

A collection of Python chatbots ranging from simple rule-based systems to more sophisticated conversational agents.

πŸ“‹ Overview

This project contains multiple chatbot implementations:

  1. Simple Chatbot (simple_chatbot.py) - Basic rule-based chatbot using pattern matching
  2. Enhanced Chatbot (enhanced_chatbot.py) - Advanced chatbot with memory and conversation context
  3. NLP Chatbot (nlp_chatbot.py) - Natural language processing chatbot with sentiment analysis

πŸš€ Quick Start

Prerequisites

  • Python 3.7 or higher
  • Terminal or command prompt

Basic Setup

  1. Clone or download this project to your local machine
  2. Navigate to the project directory:
    cd python-chatbot

Running the Simple Chatbot

python3 simple_chatbot.py

Features:

  • Basic conversation patterns (greetings, questions, etc.)
  • Random response selection
  • Simple pattern matching
  • Exit commands

Running the Enhanced Chatbot

python3 enhanced_chatbot.py

Features:

  • Conversation memory and context
  • User name recognition and storage
  • Session statistics
  • Conversation history saving
  • Context-aware responses
  • Special commands (stats)

Running the NLP Chatbot

python3 nlp_chatbot.py

Features:

  • All enhanced chatbot features
  • Sentiment analysis with mood indicators
  • Emotion detection
  • Intent recognition
  • Advanced conversation analytics

πŸ“¦ Installation (For Advanced Features)

For the NLP version and additional features, install dependencies:

# Install optional dependencies
pip3 install -r requirements.txt

# For NLTK (if using NLP features)
python3 -c "import nltk; nltk.download('punkt'); nltk.download('vader_lexicon')"

πŸ’¬ Usage Examples

Simple Chatbot Interaction

πŸ€– ChatBot: Hello! I'm a simple chatbot. Type 'quit' or 'bye' to exit.
==================================================
πŸ‘€ You: Hello there!
πŸ€– ChatBot: Hi there! What's on your mind?
πŸ‘€ You: What's your name?
πŸ€– ChatBot: My name is ChatBot. What's yours?
πŸ‘€ You: How are you?
πŸ€– ChatBot: I'm doing great, thank you for asking!
πŸ‘€ You: bye
πŸ€– ChatBot: Goodbye! It was nice chatting with you!

Enhanced Chatbot Interaction

πŸ€– Enhanced ChatBot: Hello! I'm an enhanced chatbot with memory.
   I can remember our conversation and get to know you better!
   Type 'quit', 'bye', or 'stats' for statistics, or just start chatting!
======================================================================
πŸ‘€ You: Hi, I'm John
πŸ€– Enhanced ChatBot: Nice to meet you, John! I'll remember that.
πŸ‘€ You: What's the weather like?
πŸ€– Enhanced ChatBot: I don't have access to real weather data, but I hope it's nice where you are! How's the weather on your end?
πŸ‘€ You: stats
πŸ“Š Session Stats:
   Duration: 0:01:23
   Messages: 4
   Your name: John
πŸ‘€ You: Do you remember what I said earlier?
πŸ€– Enhanced ChatBot: Yes, I remember we talked about that! You said: 'What's the weather like?'

πŸ”§ Customization

Adding New Responses

Edit the responses dictionary in either chatbot file:

self.responses = {
    'new_category': [
        "Response 1",
        "Response 2",
        "Response 3"
    ]
}

Adding New Patterns

Add regex patterns to detect new intents:

self.patterns = {
    'new_pattern': re.compile(r'\b(keyword1|keyword2)\b', re.IGNORECASE)
}

πŸ“ File Structure

python-chatbot/
β”œβ”€β”€ simple_chatbot.py      # Basic rule-based chatbot
β”œβ”€β”€ enhanced_chatbot.py    # Chatbot with memory and context
β”œβ”€β”€ nlp_chatbot.py         # NLP-powered chatbot with sentiment analysis
β”œβ”€β”€ run_chatbot.py         # Easy launcher for all chatbots
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ README.md             # This file
β”œβ”€β”€ LICENSE               # MIT License
└── conversation_*.json   # Saved conversation logs (generated)

🎯 Features Comparison

Feature Simple Enhanced NLP
Basic Conversation βœ… βœ… βœ…
Pattern Matching βœ… βœ… βœ…
Conversation Memory ❌ βœ… βœ…
User Recognition ❌ βœ… βœ…
Context Awareness ❌ βœ… βœ…
Session Statistics ❌ βœ… βœ…
Conversation Saving ❌ βœ… βœ…
Sentiment Analysis ❌ ❌ βœ…
Intent Recognition ❌ ❌ βœ…
Entity Extraction ❌ ❌ βœ…

πŸ› οΈ Advanced Configuration

Environment Variables

You can set these environment variables for customization:

export CHATBOT_NAME="YourBotName"
export CHATBOT_SAVE_CONVERSATIONS="true"
export CHATBOT_LOG_LEVEL="INFO"

Conversation Storage

Enhanced chatbot saves conversations as JSON files:

  • Location: conversation_YYYYMMDD_HHMMSS.json
  • Format: Structured JSON with timestamps and metadata

πŸ” Troubleshooting

Common Issues

  1. Permission Error: Make sure Python files are executable

    chmod +x simple_chatbot.py
    chmod +x enhanced_chatbot.py
  2. Module Not Found: Ensure you're using Python 3.7+

    python3 --version
  3. Encoding Issues: The chatbots use UTF-8 encoding for emoji support

πŸ“š Learning Resources

To understand and extend these chatbots:

  1. Python Regex: Learn about pattern matching with regular expressions
  2. JSON Handling: Understanding data serialization for conversation storage
  3. Object-Oriented Programming: Classes and methods in Python
  4. Natural Language Processing: For advanced chatbot features

🎨 Future Enhancements

Planned features:

  • Web interface using Flask
  • Voice input/output capability
  • Integration with external APIs
  • Machine learning-based responses
  • Multi-language support
  • Plugin system for extensions

🀝 Contributing

Feel free to fork this project and submit improvements! Some ideas:

  • Add new conversation patterns
  • Improve response quality
  • Add new features
  • Fix bugs or optimize performance

πŸ“„ License

This project is open source and available under the MIT License.


Happy Chatting! πŸŽ‰

For questions or suggestions, feel free to reach out or create an issue in the repository.

About

A collection of Python chatbots with basic, enhanced, and NLP features

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published