This project demonstrates the deployment of a sentiment analysis model using LSTM, a web service, and a deployment pipeline with Docker and Kubernetes. The sentiment analysis model is built using TensorFlow, and the web service is implemented in Python with Flask. The MySQL database is hosted on AWS RDS. Below is a comprehensive guide on setting up and running the entire system.
- AI Model Development
- Web Service Creation
- MySQL Database Interaction
- Containerization with Docker
- Deployment with Kubernetes
- Documentation
- Bonus Features
The sentiment analysis model is developed using LSTM, achieving an accuracy of 87%. Python is used as the programming language, and TensorFlow serves as the machine learning framework.
Note: To obtain the model pickle file (sentiment_model.h5), run the notebook.ipynb provided in the repository.
A web service is implemented in Python using Flask to serve the sentiment analysis model. The service exposes an API endpoint allowing users to submit text snippets and receive model predictions. The service logs prediction requests and results in a MySQL database hosted on AWS RDS.
For MySQL database interaction, the user needs to enter the following details:
- Host
- User
- Password
- Database Name
Use the sql.py
Python file to retrieve information from the database.
The AI model and the web service are containerized using Docker. The Dockerfile specifies the environment, dependencies, and how the application should run. The container exposes port 5002, and Gunicorn is used to run the Flask app.
The deployment is managed using Kubernetes. The deployment.yaml
file defines a Deployment and a Service. The Deployment ensures the desired number of replicas (pods) are running, and the Service exposes the web service externally.
Follow these steps to set up and run the project:
-
Clone the Repository:
git clone https://github.com/gunaxprofessional/Sentiment-Analysis-Model-Deployment-Pipeline.git cd Sentiment-Analysis-Model-Deployment-Pipeline
-
Install Dependencies:
pip install -r requirements.txt
-
Run the Web Service Locally:
python app.py
Access the service at http://localhost:5002.
-
Build Docker Image:
docker build -t sentimentdockerimg .
-
Run Docker Container:
docker run -p 5002:5002 sentimentdockerimg
Access the service at http://localhost:5002.
-
Kubernetes Deployment:
Apply the Kubernetes deployment configuration:
kubectl apply -f deployment.yaml
Start minikube:
minikube start
Monitor the deployment:
kubectl get deployments kubectl get pods kubectl get services
Access the service based on the external IP or NodePort provided.
Open Kubernetes Dashboard:
minikube dashboard
Get Service URL:
minikube service sentiment-analysis-service --url
-
Front-End Interface:
A simple front-end interface is added for user interaction. Access the interface at http://localhost:5002.