Skip to content

Commit f54a6a3

Browse files
authored
Merge pull request #541 from mlrun/1.5.x-dev
1.5.x dev
2 parents a751bb6 + 05ae880 commit f54a6a3

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

stocks-prediction/04_model_serving.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
}
299299
],
300300
"source": [
301+
"fn.spec.readiness_timeout = 60 * 20 # 20 minutes\n",
301302
"address = fn.deploy()"
302303
]
303304
},

stocks-prediction/src/serving_stocks.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@
2727
import os
2828
import time
2929

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

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

98100
class StocksModel(PyTorchModelServer):

0 commit comments

Comments
 (0)