-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_model_code_locally.py
More file actions
30 lines (22 loc) · 981 Bytes
/
test_model_code_locally.py
File metadata and controls
30 lines (22 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from frogml.sdk.model.tools import run_local
import json
import pandas as pd
from main import *
if __name__ == '__main__':
# Create a new instance of the model from __init__.py
m = load_model()
# Create test data with a sample ISBN
test_data = pd.DataFrame({
'isbn': ['9780553103540'] # A Game of Thrones ISBN
})
# Create the DataFrame and convert it to JSON
json_df = test_data.to_json()
print("\n\nPREDICTION REQUEST:\n\n", test_data)
# Run local inference using the model and print the prediction
# The run_local function is part of the frogml library and allows for local testing of the model
prediction = run_local(m, json_df)
prediction_data = json.loads(prediction)
# Extract the prediction results
prediction_df = pd.DataFrame(prediction_data)
print(f"\n\nPREDICTION RESPONSE:\n\n{prediction_df}")
print(f"\n\nRecommended {len(prediction_df)} books for ISBN: {test_data.iloc[0]['isbn']}")