Skip to content

Instantly share code, notes, and snippets.

Avatar
😎

Tivadar Danka cosmic-cortex

😎
View GitHub Profile
@cosmic-cortex
cosmic-cortex / predict_skeleton.py
Last active Jan 29, 2020
Skeleton of the predict endpoint
View predict_skeleton.py
@app.post("/predict", response_model=PredictResponse)
def predict(input: PredictRequest):
return PredictResponse(data=[0.0])
View predict_final.py
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 Jan 27, 2020
FastAPI application skeleton
View main_skeleton.py
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 Jan 27, 2020
Abstract interface for the machine learning model
View model_abstract.py
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 Jan 27, 2020
Implementation of the machine learning model for the API
View model.py
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):