Skip to content

Instantly share code, notes, and snippets.

View aballah-chamakh's full-sized avatar

abdallah-chamakh aballah-chamakh

View GitHub Profile
from django.conf.urls import include
from django.urls import path
from rest_framework import routers
from .views import InferenceViewSet
router = routers.DefaultRouter()
router.register('inference', InferenceViewSet)
urlpatterns = [
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework import viewsets,status,generics
from .serializers import InferenceSerializer
from .models import Inference
from celery.result import AsyncResult
class InferenceViewSet(viewsets.ModelViewSet):
serializer_class = InferenceSerializer
from rest_framework import serializers
from .models import Inference
from .tasks import run_inference
class InferenceSerializers(serializers.ModelSerializers):
class Meta :
model = Inference
fields = ('name','result')
def create(self,validated_data):
from django.db import models
class Inference(models.Model):
name = models.CharField(max_length=255)
result = models.CharField(max_length=255)
def __str__(self):
return '{name} => result : {result}'.format(name=self.name,result=self.result)
FROM python:3.6 # base image
RUN mkdir src # create a src directory
WORKDIR /src # change directory to src
ADD . /src/ # add the django code to src
RUN pip install requirements.txt # install the python library
def predict(x,w1,w2,w3,b1,b2,b3) :
l1 = sigmoid(np.dot(x,w1) + b1)
l2 = sigmoid(np.dot(l1,w2) + b2)
l3 = sigmoid(np.dot(l2,w3) + b3)
print(l3.round(decimals=2))
test = x[0]
predict(test,*params)
params = w1,w2,w3,b1,b2,b3
for i in range(0,10000) :
params = train(x,y,*params)
def train(x,y,w1,w2,w3,b1,b2,b3) :
# feed forward
inp_l = x
l1 = sigmoid(np.dot(inp_l,w1) + b1)
l2 = sigmoid(np.dot(l1,w2) + b2)
l3 = sigmoid(np.dot(l2,w3) + b3)
#backpropagation
delta_l3 = (y - l3)*sigmoid_prime(l3)
def sigmoid_prime(x):
return x*(1-x)
def sigmoid(x):
return 1/(1+np.exp(-x))