Skip to content

Instantly share code, notes, and snippets.

View cosmic-cortex's full-sized avatar
😎

Tivadar Danka cosmic-cortex

😎
View GitHub Profile
@cosmic-cortex
cosmic-cortex / predict_skeleton.py
Last active January 29, 2020 12:37
Skeleton of the predict endpoint
@app.post("/predict", response_model=PredictResponse)
def predict(input: PredictRequest):
return PredictResponse(data=[0.0])
@cosmic-cortex
cosmic-cortex / predict_final.py
Last active January 27, 2020 15:37
predict endpoint
import numpy as np
from fastapi import Depends
from .ml.model import get_model
@app.post("/predict", response_model=PredictResponse)
def predict(input: PredictRequest, model: Model = Depends(get_model)):
X = np.array(input.data)
y_pred = model.predict(X)
@cosmic-cortex
cosmic-cortex / main_skeleton.py
Last active January 27, 2020 13:55
FastAPI application skeleton
from typing import List
from fastapi import FastAPI
from pydantic import BaseModel
class PredictRequest(BaseModel):
data: List[List[float]]
@cosmic-cortex
cosmic-cortex / model_abstract.py
Created January 27, 2020 12:48
Abstract interface for the machine learning model
class Model:
def train(self, X, y):
pass
def predict(self, X):
pass
def save(self):
pass
@cosmic-cortex
cosmic-cortex / model.py
Last active January 27, 2020 14:43
Implementation of the machine learning model for the API
import joblib
import numpy as np
from pathlib import Path
from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import load_boston
class Model:
def __init__(self, model_path: str = None):