Wilsven / ml-dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Machine Learning Development

Virtual environment

conda create -n your_env_name python=3.11 -y  # create a virtual environment
conda activate your_env_name  # activate your virtual environment

Install dependencies

cd app/api  # head to where the requirements.txt is located
conda install --file requirements.txt -y   # install dependencies

Start the Flask server

python app.py

Send a curl command

curl -X POST -H "Content-Type: application/json" -d '{"text": "May the Force be with you."}' 0.0.0.0:5000/predict

{
    "label": "Positive",
    "pred": 1,
    "text": "May the Force be with you."
}

docker-compose

Build the image then run the container based on that image.

docker compose up --build

Testing with Postman

  1. Change the request method to POST and set the endpoint to http://localhost:5000/predict in Postman.

  2. Under the Headers tab, type Content-Type for the key and application/json for the value.

  3. Under the Body tab, select raw and enter the following:

    {
        "text": "May the Force be with you."
    }
    
  4. Hit send and you will see the same output as above during production

Docker Hub

docker compose push

Remove Docker images and containers

docker images  # view all images
docker rmi -f <IMAGE_ID>  # remove image
docker ps -a  # list all containers
docker rm -f <CONTAINER_ID>  # remove container

Pull the image from Docker Hub and run

Now that your local is clean, let's confirm that we successfully pushed the Docker image into Docker Hub by running the following:

docker run -p5000:5000 your_username/your_app_name

You can follow the same steps above and test with Postman to confirm that it is working as expected.

About

License:MIT License


Languages

Language:Jupyter Notebook 72.4%Language:Python 26.4%Language:Dockerfile 1.2%