An intelligent FAQ Chatbot built using Python, Streamlit, Natural Language Processing (NLP), TF-IDF Vectorization, and Cosine Similarity.
This chatbot helps users get instant answers to frequently asked questions by matching user queries with the most relevant stored FAQs instead of using hardcoded keyword matching.
It provides a clean chat-style interface, confidence score for responses, session-based chat history, and security improvements for safe deployment.
- Interactive chat-style UI using Streamlit
- FAQ matching using TF-IDF + Cosine Similarity
- NLP preprocessing using NLTK
- Confidence score for each response
- Sidebar with example questions
- Clear chat functionality
- Session-based chat history
- Secure JSON loading and validation
- XSS protection using HTML escaping
- Input length limitation
- Session-based rate limiting
- Exception-safe error handling
- Automatic chat history trimming
- Streamlit
- Python
- NLTK
- Scikit-learn
- JSON
- TF-IDF Vectorizer
- Cosine Similarity
FAQ_Chatbot/
β
βββ app.py
βββ chatbot.py
β
βββ data/
β βββ faqs.json
β
βββ requirements.txt
βββ README.md
-
FAQs are stored inside
faqs.json -
Questions are preprocessed using NLP:
- Lowercasing
- Tokenization
- Stopword removal
-
TF-IDF converts text into numerical vectors
-
Cosine similarity compares user input with stored FAQs
-
Best matching answer is returned to the user
-
Confidence score is displayed with the answer
This project includes fixes for common chatbot security vulnerabilities:
- XSS prevention for unsafe HTML rendering
- Path traversal protection for JSON loading
- JSON schema validation
- Input length limitation (max 500 chars)
- Session-based request limiting
- Exception-safe error handling
- Chat history memory control
These improvements make the chatbot safer and more production-ready.
git clone https://github.com/your-username/faq-chatbot.git
cd faq-chatbotpython -m venv .venvActivate environment:
.venv\Scripts\activatesource .venv/bin/activatepip install -r requirements.txtstreamlit run app.pyThe app will open in your browser automatically.
Usually at:
http://localhost:8501
streamlit
nltk
scikit-learn
numpy
- What is your return policy?
- How do I track my order?
- Do you offer free shipping?
- How can I contact support?
- What payment methods do you accept?
- Voice-based chatbot
- Admin panel for managing FAQs
- Database integration
- Hugging Face transformer models
- Context-aware chatbot
- User feedback learning system
- Deployment on Streamlit Cloud
This project was built as part of a student internship task at CodeAlpha.