Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs and update dependencies #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added backend/server/apps/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion backend/server/apps/endpoints/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class EndpointsConfig(AppConfig):
name = 'endpoints'
name = 'apps.endpoints'
9 changes: 6 additions & 3 deletions backend/server/apps/endpoints/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.db import models


class Endpoint(models.Model):
'''
The Endpoint object represents ML API endpoint.
''' ML API endpoint.

Attributes:
name: The name of the endpoint, it will be used in API URL,
Expand All @@ -13,6 +13,7 @@ class Endpoint(models.Model):
owner = models.CharField(max_length=128)
created_at = models.DateTimeField(auto_now_add=True, blank=True)


class MLAlgorithm(models.Model):
'''
The MLAlgorithm represent the ML algorithm object.
Expand All @@ -34,6 +35,7 @@ class MLAlgorithm(models.Model):
created_at = models.DateTimeField(auto_now_add=True, blank=True)
parent_endpoint = models.ForeignKey(Endpoint, on_delete=models.CASCADE)


class MLAlgorithmStatus(models.Model):
'''
The MLAlgorithmStatus represent status of the MLAlgorithm which can change during the time.
Expand All @@ -49,7 +51,8 @@ class MLAlgorithmStatus(models.Model):
active = models.BooleanField()
created_by = models.CharField(max_length=128)
created_at = models.DateTimeField(auto_now_add=True, blank=True)
parent_mlalgorithm = models.ForeignKey(MLAlgorithm, on_delete=models.CASCADE, related_name = "status")
parent_mlalgorithm = models.ForeignKey(MLAlgorithm, on_delete=models.CASCADE, related_name="status")


class MLRequest(models.Model):
'''
Expand Down
8 changes: 3 additions & 5 deletions backend/server/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['0.0.0.0']
ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework', # add django rest framework
# apps
'rest_framework',
'apps.endpoints',
'apps.ml'
]
Expand Down Expand Up @@ -84,6 +81,7 @@
}
}

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
Expand Down
8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ version: '2'
services:
nginx:
restart: always
image: nginx:1.12-alpine
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
ports:
- 8000:8000
volumes:
Expand All @@ -14,9 +16,11 @@ services:
context: .
dockerfile: ./docker/backend/Dockerfile
entrypoint: /app/docker/backend/wsgi-entrypoint.sh
# stdin_open: true # docker run -i
# tty: true # docker run -t
volumes:
- static_volume:/app/backend/server/static
expose:
- 8000
volumes:
static_volume: {}
static_volume: {}
22 changes: 10 additions & 12 deletions docker/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
FROM ubuntu:xenial

RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \
apt-get update && \
apt-get install -y python3.6 python3.6-dev python3-pip
FROM python:3.7

WORKDIR /app
COPY requirements.txt .
RUN rm -f /usr/bin/python && ln -s /usr/bin/python3.6 /usr/bin/python
RUN rm -f /usr/bin/python3 && ln -s /usr/bin/python3.6 /usr/bin/python3

RUN pip3 install -r requirements.txt
RUN pip3 install gunicorn==19.9.0
RUN python --version
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN pip install gunicorn

ADD ./backend /app/backend
ADD ./docker /app/docker
ADD ./research /app/research

#RUN mkdir -p /app/backend/server/staticfiles
RUN mkdir -p /app/backend/server/staticfiles
RUN mkdir -p /app/backend/server/static




7 changes: 5 additions & 2 deletions docker/backend/wsgi-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#!/usr/bin/env bash

echo "Start backend server"
echo "Starting backend django server"
until cd /app/backend/server
do
echo "Waiting for server volume..."
done

echo "Running manage.py migrate"
until ./manage.py migrate
do
echo "Waiting for database to be ready..."
sleep 2
done

echo "Running manage.py collectstatic"
./manage.py collectstatic --noinput

gunicorn server.wsgi --bind 0.0.0.0:8000 --workers 4 --threads 4
echo "Running manage.py gunicorn on port 8000"
gunicorn server.wsgi --bind :8000 --workers 4 --threads 4
4 changes: 2 additions & 2 deletions docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM nginx:latest

FROM nginx:1.13.12-alpine
CMD ["nginx", "-g", "daemon off;"]
CMD ["nginx", "-g", "daemon off;"]
19 changes: 10 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Django==2.2.13
django-filter==2.2.0
djangorestframework==3.10.3
joblib==0.14.0
Markdown==3.1.1
numpy==1.17.3
pandas==0.25.2
requests==2.22.0
scikit-learn==0.21.3
Django
django-filter
djangorestframework
gunicorn
joblib
Markdown
numpy
pandas
requests
scikit-learn
83 changes: 70 additions & 13 deletions research/ab_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"import json # will be needed for saving preprocessing details\n",
"import numpy as np # for data manipulation\n",
"import pandas as pd # for data manipulation\n",
"from sklearn.model_selection import train_test_split # will be used for data split\n",
"from sklearn.model_selection import train_test_split # will be used for data split\n",
"import requests"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -174,7 +174,7 @@
"4 0 0 40 Cuba <=50K "
]
},
"execution_count": 2,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -192,7 +192,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -202,17 +202,74 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<Response [200]>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"for i in range(100):\n",
" input_data = dict(X_test.iloc[i])\n",
" target = y_test.iloc[i]\n",
" r = requests.post(\"http://127.0.0.1:8000/api/v1/income_classifier/predict?status=ab_testing\", input_data)\n",
" response = r.json()\n",
" # provide feedback\n",
" requests.put(\"http://127.0.0.1:8000/api/v1/mlrequests/{}\".format(response[\"request_id\"]), {\"feedback\": target})"
" response = requests.post(\"http://127.0.0.1:8000/api/v1/income_classifier/predict?status=ab_testing\", input_data)\n",
"response"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'probability': 0.15, 'label': '<=50K', 'status': 'OK', 'request_id': 58}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"js = response.json()\n",
"js"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Response [200]>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"requests.put(\"http://127.0.0.1:8000/api/v1/mlrequests/{}\".format(js[\"request_id\"]), {\"feedback\": target})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"visit http://127.0.0.1:8000/admin/"
]
},
{
Expand All @@ -225,9 +282,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "venv"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -239,7 +296,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.7.10"
}
},
"nbformat": 4,
Expand Down
Binary file modified research/encoders.joblib
Binary file not shown.
Binary file modified research/extra_trees.joblib
Binary file not shown.
Binary file modified research/random_forest.joblib
Binary file not shown.
Loading