Skip to content

Commit

Permalink
Merge pull request #541 from mlrun/1.5.x-dev
Browse files Browse the repository at this point in the history
1.5.x dev
  • Loading branch information
aviaIguazio authored Nov 28, 2023
2 parents a751bb6 + 05ae880 commit f54a6a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions stocks-prediction/04_model_serving.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
}
],
"source": [
"fn.spec.readiness_timeout = 60 * 20 # 20 minutes\n",
"address = fn.deploy()"
]
},
Expand Down
18 changes: 10 additions & 8 deletions stocks-prediction/src/serving_stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@
import os
import time

warnings.filterwarnings("ignore")
def log_results(df: pd.DataFrame):
# writing to tsdb
if "V3IO_USERNAME" in os.environ:
framesd = os.getenv("V3IO_FRAMESD",'framesd:8081')
client = v3f.Client(framesd, container=os.getenv('V3IO_CONTAINER', 'projects'))
kv_table_path = '/stocks-'+ os.environ['V3IO_USERNAME'] + '/artifacts/stocks_prediction'
client.write('kv', kv_table_path, dfs=df, index_cols=['datetime','tickers'])
print(f'writing prediction to kv at projects{kv_table_path} ...')


def preprocess(event):
vector_name = event['vector_name']
Expand Down Expand Up @@ -85,14 +93,8 @@ def postprocess(event):
df['true'] = event['outputs']['labels']
df['prediction'] = (df['prediction']*event['outputs']['price_std']) + event['outputs']['price_mean']
df['true'] = (df['true']*event['outputs']['price_std']) + event['outputs']['price_mean']
df2 = df.copy()
df['datetime'] = df['datetime'].apply(lambda x: x.strftime('%Y-%m-%d %H:%M:%S'))
# writing to tsdb
framesd = os.getenv("V3IO_FRAMESD",'framesd:8081')
client = v3f.Client(framesd, container=os.getenv('V3IO_CONTAINER', 'projects'))
kv_table_path = '/stocks-'+ os.environ['V3IO_USERNAME'] + '/artifacts/stocks_prediction'
client.write('kv', kv_table_path, dfs=df, index_cols=['datetime','tickers'])
print(f'writing prediction to kv at projects{kv_table_path} ...')
log_results(df)
return [df.values.tolist(),list(df.columns)]

class StocksModel(PyTorchModelServer):
Expand Down

0 comments on commit f54a6a3

Please sign in to comment.