Skip to content

Instantly share code, notes, and snippets.

Avatar

naxty

  • Karlsruhe, Germany
View GitHub Profile
View sort.example.ts
type Category = {
name: string
tags: string[]
}
type Product = {
name: string
description: string
}
let products: Array<Product> =[
@naxty
naxty / sort.ts
Created Aug 8, 2020
Generic function to sort array with objects in TypeScript alphabetically.
View sort.ts
const sort = <Element extends {name: string}>(array: Array<Element>) => {
return array.sort((a: Element, b: Element) => {
if (a.name < b.name){
return -1;
}
if (a.name > b.name){
return 1;
}
return 0;
})
@naxty
naxty / sortCategories.ts
Created Aug 8, 2020
Sort array of objects alphabetically in TypeScript
View sortCategories.ts
type Category = {
name: string
}
const categories:Array<Category> = [
{
name: "Travel"
},
{
name: "Electronics"
@naxty
naxty / cortex.yaml
Last active Oct 7, 2019
Cortex YAML for boston housing model
View cortex.yaml
- kind: deployment
name: boston-housing
- kind: api
name: linear-regression
model: s3://cortex-07af1aa182/boston_housing/linear_regression.onnx
request_handler: boston_handler.py
@naxty
naxty / boston_handler.py
Created Oct 4, 2019
Boston features handler for cortex
View boston_handler.py
from pydantic import BaseModel
import numpy as np
class HousingFeatures(BaseModel):
CRIM: float
ZN: float
INDUS: float
CHAS: float
@naxty
naxty / cortex_install.sh
Created Oct 4, 2019
Shell script to install cortex 0.8
View cortex_install.sh
# Download
curl -O https://raw.githubusercontent.com/cortexlabs/cortex/0.8/cortex.sh
# Change permissions
chmod +x cortex.sh
# Install the Cortex CLI on your machine
./cortex.sh install cli
# Set AWS credentials
export AWS_ACCESS_KEY_ID=***
export AWS_SECRET_ACCESS_KEY=***
# Configure AWS instance settings (at least 4GB memory)
View emotion_service_deployment.json
{
"apiVersion": "machinelearning.seldon.io/v1alpha2",
"kind": "SeldonDeployment",
"metadata": {
"labels": {
"app": "seldon"
},
"name": "seldon-emotion"
},
"spec": {
@naxty
naxty / rest_client.py
Created Sep 9, 2019
REST Client for local seldon core docker container
View rest_client.py
from PIL import Image
import numpy as np
import requests
path_to_image = "images/smile.jpg"
image = Image.open(path_to_image).convert('L')
resized = image.resize((64, 64))
values = np.array(resized).reshape(1, 1, 64, 64)
req = requests.post("http://localhost:5000/predict", json={"data":{"ndarray": values.tolist()}})
@naxty
naxty / Dockerfile
Created Sep 9, 2019
Dockerfile for Seldon Core Python Wrapper
View Dockerfile
FROM python:3.7-slim
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
RUN mkdir /app
WORKDIR /app
RUN mkdir model
COPY model/model.onnx model/model.onnx
COPY EmotionModel.py EmotionModel.py
@naxty
naxty / EmotionModel.py
Created Sep 9, 2019
Seldon Core Python Wrapper for Emotion Detections
View EmotionModel.py
from ngraph_onnx.onnx_importer.importer import import_onnx_file
import ngraph as ng
import numpy as np
class EmotionModel(object):
def __init__(self):
model = import_onnx_file("model/model.onnx")
runtime = ng.runtime(backend_name="CPU")
self.inference = runtime.computation(model)