Giter VIP home page Giter VIP logo

titanic-django's Introduction

๐Ÿ›ณ titanic-django

A simple example of how Django can be used to serve predictions through an API.

โ–ถ๏ธ Quickstart

๐Ÿ Create environment

Open up a terminal in the repositories root and run these commands to align your environment:

conda create -n titanic-django

conda activate titanic-django

conda install pip

pip install -r requirements.txt

๐Ÿš€ Run local Django server

This will host the API.

  • Open a terminal and navigate to the titanicapi project folder (first level, not the second). Then run:

conda activate titanic-django

(making sure you are executing from within the new environment)

Next run

python manage.py runserver

This will run a local development server of the django app. The model's API is now ready to call!

๐Ÿ“ฒ Call the API

  • Run demo.ipynb in the titanic-django conda environment once more (or any environment with requests and pandas installed)

  • You should be getting results from your server!

That's it! Congrats on your first Django model API!

โ› How to build a similar django project from scratch

  • Run the following in your desired project directory:

django-admin startproject titanicapi

python manage.py migrate

django-admin startapp api

  • Add api to installed apps in main settings

  • Add two files to api app directory:

  1. functions.py
  • here you write your functions for loading the serialized model and classifying passengers
  1. urls.py
  • here you specify the URL on which your API will sit. This will allow you to send post requests with feature data to get predictions.

  • Create APIView class in view.py with a post function to handle post requests. E.g.

get_classification(APIView)

  • Add api urls to project root urls (titanicapi/urls.py) so that the main app knows that the api urls exist. E.g.

path('api/', include('api.urls'))

  • Try running your server to see if it likes your setup. Generally Django logs are very good.

python manage.py runserver

titanic-django's People

Contributors

chrisgschon avatar

Stargazers

Farhad Batmanghelich avatar Keyvan Zare-Rami avatar Parker Dinkins avatar codelabrador avatar Thomas James avatar Javier Estraviz avatar Jacob Cannon avatar  avatar

Watchers

James Cloos avatar  avatar

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.