From f30cd5011b312460057fac0ba369bdb6bb3ba29a Mon Sep 17 00:00:00 2001 From: Kamila Date: Sun, 15 May 2022 13:24:08 +0200 Subject: [PATCH] mlflow attempt task 2 prediction registry --- Jenkinsfile_pred_reg | 28 ++++++++++++++++++++++++++++ predict_registry.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 Jenkinsfile_pred_reg create mode 100644 predict_registry.py diff --git a/Jenkinsfile_pred_reg b/Jenkinsfile_pred_reg new file mode 100644 index 0000000..f08244b --- /dev/null +++ b/Jenkinsfile_pred_reg @@ -0,0 +1,28 @@ +pipeline { + agent { + dockerfile true + } + parameters { + string( + defaultValue: 'input_example.json', + description: 'Input file name', + name: 'INPUT_FILE_NAME', + trim: false + ) + } + + stages { + stage('Stage 1') { + steps { + echo 'Hello world!' + } + } + + stage('Prediction') { + steps { + sh 'python3 predict_registry.py $INPUT_FILE_NAME' + } + } + } +} + diff --git a/predict_registry.py b/predict_registry.py new file mode 100644 index 0000000..ffe8bb7 --- /dev/null +++ b/predict_registry.py @@ -0,0 +1,32 @@ +import json +import mlflow +import numpy as np +import sys + +mlflow.set_tracking_uri("http://172.17.0.1:5000") +client =mlflow.tracking .MlflowClient() +model_version = 14 +model_name = "s449288" + +experiment = client.get_latest_versions(model_name, stages=None) +print(experiment) +print(experiment[0].source) +model = mlflow.pyfunc.load_model( + model_uri=f"models:/{model_name}/{model_version}" +) + +with open(f'{experiment[0].source}/{(sys.argv[1:])[0]}', 'r') as file: + json_data = json.load(file) + print(f"Prediction: {model.predict(np.array([json_data['inputs']]))}") + + +''' +PATH = "mlruns/14/80fe21a0804844088147d15a3cebb3e5/artifacts/lego-model" + +model = mlflow.pyfunc.load_model(PATH) + +with open(f'{PATH}/{(sys.argv[1:])[0]}', 'r') as file: + json_data = json.load(file) + print(f"Prediction: {model.predict(np.array([json_data['inputs']]))}") +''' + \ No newline at end of file