This is a simple chatbot project built using PyTorch and Flask. The chatbot is trained to respond to specific user queries or greetings and can provide answers related to predefined intents.
Before running the chatbot, make sure you have the following installed:
- Python 3.x
- PyTorch
- Flask
- NLTK (Natural Language Toolkit)
You can install the required Python packages using pip
:
pip install torch flask nltk
The project is organized as follows:
train.py
: Contains the code for training the chatbot using PyTorch.nltk_utils.py
: Helper functions for tokenization, stemming, and creating bag-of-words vectors.models.py
: Defines the neural network architecture for the chatbot.app.py
: Flask application for running the chatbot server.chat.py
: Functions for interacting with the trained chatbot model.intents.json
: Configuration file containing predefined intents and responses.
To run the chatbot, follow these steps:
-
Train the chatbot using
train.py
to create adata.pth
file containing the trained model. -
Run the Flask application using
app.py
. -
Open your web browser and navigate to http://localhost:5000 to interact with the chatbot.
You can customize and train the chatbot by modifying the intents.json
file. Add new intents, patterns, and responses to teach the chatbot how to respond to specific user inputs.
-
Edit
intents.json
to customize intents, patterns, and responses. -
Run the training script
train.py
as mentioned above.
The intents.json
file contains predefined intents such as greetings, goodbyes, and specific queries. You can customize these intents or add new ones to tailor the chatbot to your specific use case.
Here's an example of a predefined intent:
{
"tag": "greeting",
"patterns": [
"Hi",
"Hey",
"How are you",
"Is anyone there?",
"Hello",
"Good day"
],
"responses": [
"Hey :-)",
"Hello, thanks for visiting",
"Hi there, what can I do for you?",
"Hi there, how can I help?"
]
}