Last active
June 7, 2020 13:20
-
-
Save IvanNardini/2c282d5a86554fcdd1380c2b6411f6b4 to your computer and use it in GitHub Desktop.
MLOps series #2 : Deploy a Recommendation System as Hosted Interactive Web Service on AWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
This module contains the predict callback | |
''' | |
from dash.dependencies import Input, Output | |
from app import * | |
@app.callback([Output('table', component_property='columns'), Output('table', component_property='data')],[Input(component_id='uid', component_property='value')]) | |
def predict(uid): | |
columns = [] | |
products_recommended = [] | |
if uid: | |
model_path = locate_model(os.getcwd()) | |
predictions, _ = model_reader(model_path) | |
uid_predictions = get_top_n_ui(get_top(predictions), uid) | |
prediction_rank_lenght = len(uid_predictions) | |
prediction_rank_labels = ["".join([" Product", str(i)]) for i in range(1,prediction_rank_lenght)] | |
products_recommended = pd.DataFrame(list(zip(prediction_rank_labels, uid_predictions)), columns=['Product_Rank', 'Product_id']) | |
columns=[{"name": i, "id": i} for i in products_recommended.columns] | |
return columns, products_recommended.to_dict('records') | |
else: | |
return columns, products_recommended |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment