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

Remove ORM #13

Merged
merged 1 commit into from
Sep 10, 2021
Merged
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
22 changes: 10 additions & 12 deletions app/api/router/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,14 @@
from typing import List
from app.utils import my_model

from app import crud, models
from app import models
from app.database import engine
from app.database import SessionLocal


models.Base.metadata.create_all(bind=engine)


def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()


router = APIRouter(
prefix="/predict",
tags=["predict"],
Expand All @@ -33,7 +25,7 @@ def get_db():


@router.put("/insurance")
def predict_insurance(info: ModelCorePrediction, model_name: str, db: Session = Depends(get_db)):
def predict_insurance(info: ModelCorePrediction, model_name: str):
"""
Get information and predict insurance fee
param:
Expand All @@ -49,11 +41,17 @@ def predict_insurance(info: ModelCorePrediction, model_name: str, db: Session =
return:
insurance_fee: float
"""
reg_model = crud.get_reg_model(db, model_name=model_name)
query = """
SELECT model_file
FROM model_core
WHERE model_name='{}';
""".format(model_name)

reg_model = engine.execute(query).fetchone()[0]

if reg_model:
loaded_model = pickle.loads(
codecs.decode(reg_model.model_file, 'base64'))
codecs.decode(reg_model, 'base64'))

test_set = np.array([
info.age,
Expand Down
8 changes: 0 additions & 8 deletions app/crud.py

This file was deleted.