This application provides a chatbot that can respond to user queries, fetch real-time weather data, and collect user information. Users can either integrate the provided API into their own applications or websites, or use the provided Flutter application for the UI.
- Features
- Requirements
- Setup
- Running the Application
- API Endpoints
- Firebase Service Account Key
- Using the API in Your Application
- Flutter Chatbot Integration
- Specific Formats for User Queries
- License
- Weather Data Retrieval: Fetch real-time weather data from Firestore for a specified location.
- User Information Collection: Collect and store user information (name, address, phone number) in Firestore.
- Chatbot Responses: Respond to user queries using a trained neural network model.
- Time and Date Information: Provide current time and date information upon request.
- List App Users: Retrieve and display a list of app users stored in Firestore.
- Python 3.7+
- Flask
- Firebase Admin SDK
- PyTorch
- NumPy
- Clone the repository:
git clone https://github.com/nisanray/AI_ChatBot_Model_Python cd AI_ChatBot_Model_Python
- Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
- Install dependencies:
pip install -r requirements.txt
- Set up Firebase:
- Download your Firebase service account key and save it as
serviceAccountKey.jsonin the project root directory. - Ensure your Firestore database is set up with the required collections (
weather_updates,app_users).
- Download your Firebase service account key and save it as
- Train the model:
- Run the
train.pyscript to train the neural network model and generatemodel.pth:
python train.py
- Run the
- Prepare model and data files:
- Ensure
model.pth,intents.json, andtrain_data.jsonare in the project root directory.
- Ensure
-
Start the Flask server:
python app.py
-
Access the application:
- The application will be running at
http://127.0.0.1:5000/.
- The application will be running at
- Chatbot Response:
/chatbot(POST)- Request:
{ "message": "your message here", "user_id": "optional user id" } - Response:
{ "response": "chatbot response here" }
- Request:
- List Users:
/users(GET)- Response:
{ "users": [ { "user_id": "user id", "name": "user name", "address": "user address", "phone": "user phone", "timestamp": "timestamp" }, "..." ] }
- Response:
You can find the Firebase service account key by following these steps:
- Go to the Firebase Console.
- Select your project.
- Click on the gear icon next to "Project Overview" and select "Project settings".
- Navigate to the "Service accounts" tab.
- Click on "Generate new private key".
- A JSON file containing your service account key will be downloaded. Save this file as
serviceAccountKey.jsonin the root directory of your project.
Make sure to keep this file secure and do not share it publicly.
You can use the provided API endpoints to integrate the chatbot and weather functionalities into your own application or website.
- Chatbot Response: Send a POST request to
/chatbotwith a JSON payload containing the user's message. - List Users: Send a GET request to
/usersto retrieve a list of app users.
Example using requests library in Python:
import requests
# Chatbot response
response = requests.post('http://127.0.0.1:5000/chatbot', json={"message": "Hello"})
print(response.json())
# List users
response = requests.get('http://127.0.0.1:5000/users')
print(response.json())To integrate this application with a Flutter frontend, follow these steps:
-
Clone the Flutter repository:
git clone https://github.com/nisanray/FLutter-Chatbot-with-Python.git cd FLutter-Chatbot-with-Python -
Install Flutter dependencies:
flutter pub get
-
Update the API endpoint:
- Open the Flutter project and update the API endpoint in the code to point to your Flask server (e.g.,
http://127.0.0.1:5000/).
- Open the Flutter project and update the API endpoint in the code to point to your Flask server (e.g.,
-
Run the Flutter application:
flutter run
To get specific responses from the chatbot, use the following formats:
-
Storing User Information:
- Start the process by sending:
"store my info" - Follow the prompts to provide your name, address, and phone number.
- Confirm by replying
"yes".
- Start the process by sending:
-
Fetching Weather Data:
- Send a message in the format:
"weather in [location]"(e.g.,"weather in New York").
- Send a message in the format:
-
Getting Current Time:
- Send a message containing any of the following keywords:
"time","current time","what is the time","tell me the time".
- Send a message containing any of the following keywords:
-
Getting Current Date:
- Send a message containing any of the following keywords:
"date","current date","what is the date","tell me the date","day".
- Send a message containing any of the following keywords:
This project is licensed under the MIT License. See the LICENSE file for more details.#