Skip to content

MakoShar/AI-CHATBOT-WITH-NLP

Repository files navigation

# 🤖 AI Chatbot with NLP **CodTech Internship Project** *An intelligent chatbot powered by Natural Language Processing* ## 📋 Project Overview This project implements a sophisticated AI chatbot using Natural Language Processing libraries like NLTK and spaCy. The chatbot can understand user queries, analyze sentiment, extract entities, and provide intelligent responses based on a knowledge base and machine learning techniques. ## ✨ Features ### Core NLP Capabilities - **🧠 Natural Language Understanding** - Processes and understands user input intelligently - **💭 Sentiment Analysis** - Analyzes emotional tone of messages using TextBlob - **🔍 Entity Extraction** - Identifies named entities using spaCy - **📊 TF-IDF Similarity** - Finds relevant responses using cosine similarity - **🎯 Intent Detection** - Recognizes user intentions (greeting, question, help, etc.) ### Knowledge Base - **🐍 Programming Topics** - Python, AI, Machine Learning, NLP - **💡 Technology Concepts** - Detailed explanations of technical topics - **❓ Q&A System** - Predefined question-answer pairs - **🔄 Context Awareness** - Maintains conversation history and context ### User Interfaces 1. **💻 Command Line Interface** - Direct terminal interaction 2. **🌐 Web Interface (Flask)** - Modern, responsive web application 3. **📊 Streamlit Dashboard** - Interactive analytics and visualization ## 🛠️ Technologies Used ### Python Libraries - **NLTK** - Natural Language Toolkit for text processing - **spaCy** - Advanced NLP library for entity recognition - **scikit-learn** - Machine learning algorithms (TF-IDF, cosine similarity) - **TextBlob** - Sentiment analysis and text processing - **Flask** - Web framework for the web interface - **Streamlit** - Interactive web app framework with analytics - **Pandas & NumPy** - Data manipulation and analysis - **Matplotlib & Plotly** - Data visualization ### Frontend Technologies - **HTML5 & CSS3** - Modern, responsive web design - **JavaScript** - Interactive user interface - **Font Awesome** - Beautiful icons - **Bootstrap-inspired** - Clean, professional styling ## 📁 Project Structure ``` AI CHATBOT With NLP/ ├── 📄 chatbot.py # Main chatbot class and CLI interface ├── 🌐 web_app.py # Flask web application ├── 📊 streamlit_app.py # Streamlit dashboard ├── 📋 requirements.txt # Python dependencies ├── 📖 README.md # Project documentation ├── 🎨 templates/ │ └── index.html # Web interface HTML template └── 🚀 demo_examples.py # Usage examples and demos ``` ## 🚀 Installation & Setup ### Prerequisites - Python 3.8 or higher - pip package manager ### 1. Clone or Download the Project ```bash cd "AI CHATBOT With NLP" ``` ### 2. Create Virtual Environment (Recommended) ```bash python -m venv .venv .venv\Scripts\activate # Windows # source .venv/bin/activate # Linux/Mac ``` ### 3. Install Dependencies ```bash pip install -r requirements.txt ``` ### 4. Download Additional NLP Data The chatbot will automatically download required NLTK data on first run. For spaCy: ```bash python -m spacy download en_core_web_sm ``` ## 🎮 Usage Guide ### 1. Command Line Interface Run the basic chatbot in terminal: ```bash python chatbot.py ``` **Features:** - Direct conversation in terminal - Type 'stats' for conversation statistics - Type 'quit', 'bye', or 'exit' to end ### 2. Web Interface (Flask) Launch the web application: ```bash python web_app.py ``` Open your browser and go to: `http://localhost:5000` **Features:** - Modern, responsive web interface - Real-time sentiment analysis display - Conversation statistics modal - Clear chat functionality - Mobile-friendly design ### 3. Streamlit Dashboard Run the interactive dashboard: ```bash streamlit run streamlit_app.py ``` **Features:** - Interactive chat interface - Real-time analytics and visualizations - Sentiment distribution charts - Entity extraction display - Conversation flow analysis ## 🎯 Example Interactions ### Greeting ``` You: Hello! Bot: Hello! How can I help you today? ``` ### Technical Questions ``` You: What is Python? Bot: Python is a high-level programming language known for its simplicity and readability. Python was created by Guido van Rossum and first released in 1991. ``` ### Sentiment Analysis ``` You: I'm feeling frustrated with this code Bot: I understand you might be feeling frustrated. That's a good question. What specific aspect would you like to know more about? ``` ## 🧠 NLP Features Explained ### 1. Text Preprocessing - Converts text to lowercase - Removes unnecessary punctuation - Normalizes whitespace - Tokenization using NLTK ### 2. Sentiment Analysis Uses TextBlob to classify messages as: - **Positive** 😊 (polarity > 0.1) - **Negative** 😞 (polarity < -0.1) - **Neutral** 😐 (polarity between -0.1 and 0.1) ### 3. Entity Recognition Uses spaCy to extract: - Person names (PERSON) - Organizations (ORG) - Locations (GPE) - Dates and times (DATE, TIME) - And more... ### 4. Intent Detection Recognizes user intentions: - **Greeting** - Hello, hi, good morning - **Question** - What, how, why, where, when - **Goodbye** - Bye, farewell, see you - **Help** - Help, assist, support ### 5. Response Generation - **Exact matching** for common Q&A - **Topic-based responses** from knowledge base - **TF-IDF similarity** for finding relevant answers - **Context-aware** responses based on conversation history ## 📊 Analytics Features ### Conversation Statistics - Total message count - Sentiment distribution - Most mentioned entities - Conversation flow over time ### Visualizations - Pie charts for sentiment analysis - Bar charts for entity frequency - Line charts for conversation trends - Interactive Plotly charts in Streamlit ## 🔧 Customization ### Adding New Knowledge Edit the `knowledge_base` dictionary in `chatbot.py`: ```python self.knowledge_base = { "new_topic": [ "Response 1 about new topic", "Response 2 about new topic" ] } ``` ### Modifying Responses Update the `qa_pairs` dictionary for specific Q&A: ```python self.qa_pairs = { "new question": "Custom response" } ``` ### Styling the Web Interface Modify the CSS in `templates/index.html` to change: - Colors and themes - Layout and spacing - Animations and effects ## 🎓 Learning Outcomes This project demonstrates: - **NLP Implementation** - Practical use of NLTK and spaCy - **Machine Learning** - TF-IDF vectorization and similarity matching - **Web Development** - Flask and frontend technologies - **Data Visualization** - Creating interactive charts and analytics - **Software Architecture** - Clean, modular code structure - **User Experience** - Multiple interfaces for different use cases ## 🚨 Troubleshooting ### Common Issues 1. **NLTK Data Not Found** ```bash python -c "import nltk; nltk.download('all')" ``` 2. **spaCy Model Missing** ```bash python -m spacy download en_core_web_sm ``` 3. **Port Already in Use** - Change the port in `web_app.py`: `app.run(port=5001)` 4. **Dependencies Issues** ```bash pip install --upgrade -r requirements.txt ``` ## 🔮 Future Enhancements - **Voice Interface** - Speech recognition and text-to-speech - **Multi-language Support** - Support for different languages - **Database Integration** - Persistent conversation storage - **Machine Learning Training** - Custom model training on conversation data - **API Integration** - Connect to external knowledge sources - **Advanced Analytics** - More sophisticated conversation insights ## 📄 License This project is created for educational purposes as part of the CodTech internship program. ## 👤 Author **ANOOP** *CodTech Intern* *August 2025* --- ## 🙏 Acknowledgments - **CodTech** for the internship opportunity - **NLTK Team** for the natural language processing toolkit - **spaCy Team** for the advanced NLP library - **Open Source Community** for the amazing libraries and tools --- *Happy Chatting! 🤖💬* # AI-CHATBOT-WITH-NLP

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors