Coder Social home page Coder Social logo

tanujjain / deploy-ml-model Goto Github PK

View Code? Open in Web Editor NEW
82.0 7.0 70.0 12 KB

Deploying a simple machine learning model to an AWS ec2 instance using flask and docker.

License: MIT License

Dockerfile 3.72% Python 15.74% Jupyter Notebook 80.54%
webservice docker flask machine-learning aws ec2-instance ai

deploy-ml-model's Introduction

Serve a Machine Learning Model as a Webservice

Serving a simple machine learning model as a webservice using flask and docker.

Getting Started

  1. Use Model_training.ipynb to train a logistic regression model on the iris dataset and generate a pickled model file (iris_trained_model.pkl)
  2. Use app.py to wrap the inference logic in a flask server to serve the model as a REST webservice:
    • Execute the command python app.py to run the flask app.
    • Go to the browser and hit the url 0.0.0.0:80 to get a message Hello World! displayed. NOTE: A permission error may be received at this point. In this case, change the port number to 5000 in app.run() command in app.py. (Port 80 is a privileged port, so change it to some port that isn't, eg: 5000)
    • Next, run the below command in terminal to query the flask server to get a reply 2 for the model file provided in this repo:
       curl -X POST \
       0.0.0.0:80/predict \
       -H 'Content-Type: application/json' \
       -d '[5.9,3.0,5.1,1.8]'
    
  3. Run docker build -t app-iris . to build the docker image using Dockerfile. (Pay attention to the period in the docker build command)
  4. Run docker run -p 80:80 app-iris to run the docker container that got generated using the app-iris docker image. (This assumes that the port in app.py is set to 80)
  5. Use the below command in terminal to query the flask server to get a reply 2 for the model file provided in this repo:
        curl -X POST \
        0.0.0.0:80/predict \
        -H 'Content-Type: application/json' \
        -d '[5.9,3.0,5.1,1.8]'
    

For details on floating the containerized app on AWS ec2 instance, see the blog.

LICENSE

See LICENSE for details.

deploy-ml-model's People

Contributors

tanujjain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

deploy-ml-model's Issues

Getting error while sending test data using curl in local server

Getting error while sending test data using curl in local server
app.py: return self.view_functionsrule.endpoint
File "app.py", line 28, in get_prediction
data = np.array(data)[np.newaxis, :] # converts shape from (4,) to (1, 4)
IndexError: too many indices for array
127.0.0.1 - - [31/Mar/2020 16:06:23] "�[35m�[1mPOST /predict HTTP/1.1�[0m" 500 -
_

Curl post: _curl -X POST 127.0.0.1:5000/predict -H 'Content-Type:application/json' -d '[5.9,3.0,5.1,1.8]'

<title>500 Internal Server Error</title>

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

_

Issue with post request

Hello,

I have followed the instruction after passing the post request, where can I see the result of the request?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.