Skip to content

nsb700/association-mining-webapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MACHINE LEARNING MODEL DEPLOYED AS AN API WEB APPLICATION


Description :-

This web application provides an API to access associations between diagnoses and medical services. The data powering this web application is at https://github.com/nsb700/association_mining_demo. The API URL allows retrieving associations for a diagnosis code. Response is a json for all related services and relevant lift scores.


Setup :-

(1) Create a virtual environment :- (skip if one of interest already exists)

cd ~/
mkdir  my_dir_for_venvs
cd my_dir_for_virtual_envs
python3 -m venv association-mining-webapp-venv

(2) Activate the virtual environment :-

source ~/my_dir_for_venvs/association-mining-webapp-venv/bin/activate

(3) Clone this repository :-

cd ~/
git clone https://github.com/nsb700/association-mining-webapp.git association-mining-webapp

(4) Install required dependencies by referring to requirements.txt :-

cd ~/association-mining-webapp
pip install -r requirements.txt

(5) Install Docker for relevant operating system - https://docs.docker.com/engine/install/

Minikube is a local implementation of Kubernetes. Then execute the following -

minikube start --driver=docker

(7) Install kubectl for relevant operating system - https://kubernetes.io/docs/tasks/tools/

This allows one to run commands against Kubernetes cluster which in this case is minikube.

(8) Create account on dockerhub https://hub.docker.com/ and create a repository.

Dockerhub is a container registry. We will push our container image to a registry. After creating the repository, it shows the repository name and its push command. The command displayed looks like this-

docker push <dockerhub_username>/<repository_name>:tagname

(9) Build docker image :-

cd ~/association-mining-webapp
docker build -t <dockerhub_username>/<repository_name>:0.0.1 .
  • -t is a parameter for a tag of an image
  • 0.0.1 just happens to be the tag of our choice.

(10) Push docker image (command available from step 8 above) :-

cd ~/association-mining-webapp
docker push <dockerhub_username>/<repository_name>:0.0.1

(11) Test web application by running docker image :-

docker run -p 8080:80 <dockerhub_username>/<repository_name>:0.0.1

This tells docker to run the container image locally. Here we are telling this command to port forward HTTP request from our localhost at port 8080 to port 80 of the container. Open the browser and enter this URL: http://localhost:8080/associations/diagnosis_code/M19.041 Output is something like this - img_1.png

(12) Create Pods in the Kubernetes cluster:-

cd ~/association-mining-webapp/kubernetes
minikube kubectl -- apply -f .

Check if pods are generated:

minikube kubectl get pods

img.png

This means that the pods (replicated to 3 instances as per 'replicas' in deployment.yaml), are running. Each pod is running our container image which is running our web application.

(13) Start the web application on any one of our pods :-

minikube kubectl port-forward associations-api-978dffb4f-lpr28  30080:80
  • Here we are telling this command to port forward HTTP request from our localhost at port 30080 to port 80 of service.
  • The service will get the request at port 80 and forward the request to the pod/s at port 80 (see service.yaml 'port' and 'targetPort').
  • The pod/s get the request at port 80 where it is listening (see deployment.yaml 'containerPort').
  • The pod/s then forward/s this request to the uvicorn server which is also listening at port 80 (see Dockerfile CMD).

Issue HTTP requests to the web application :-