Update template_gradio_interface.py
Browse files- template_gradio_interface.py +3 -32
template_gradio_interface.py
CHANGED
|
@@ -14,33 +14,7 @@ import yaml
|
|
| 14 |
# import time
|
| 15 |
# import cv2
|
| 16 |
# from prediction_coatings import predict
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def predict(
|
| 20 |
-
model_path,
|
| 21 |
-
data,
|
| 22 |
-
encoder,
|
| 23 |
-
minmax_scaler_inputs,
|
| 24 |
-
minmax_scaler_targets,
|
| 25 |
-
categorical_columns,
|
| 26 |
-
numerical_columns,
|
| 27 |
-
target_columns,
|
| 28 |
-
explainer,
|
| 29 |
-
use_in_gradio=False,
|
| 30 |
-
):
|
| 31 |
-
# model = tf.keras.models.load_model(model_path)
|
| 32 |
-
# if use_in_gradio:
|
| 33 |
-
# data = encode_categorical(data, categorical_columns, encoder=one_hot_scaler, fit=False)
|
| 34 |
-
# data = scale_numerical(data, numerical_columns, scaler=minmax_scaler_inputs, fit=False)
|
| 35 |
-
# return model.predict(data), data.columns, explainer.shap_values(data[-10:])
|
| 36 |
-
return 34, 10, 45, 10, None
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def unpickle_file(path):
|
| 40 |
-
with open(path, "rb") as file:
|
| 41 |
-
unpickler = pickle.Unpickler(file)
|
| 42 |
-
unpickled_file = unpickler.load()
|
| 43 |
-
return unpickled_file
|
| 44 |
|
| 45 |
|
| 46 |
def call_predict(inference_dict, cols_order):
|
|
@@ -48,11 +22,6 @@ def call_predict(inference_dict, cols_order):
|
|
| 48 |
Encapsulates the predict function from utils to pass the config, and to put the data in the right format
|
| 49 |
"""
|
| 50 |
|
| 51 |
-
categorical_columns = ""
|
| 52 |
-
numerical_columns = ""
|
| 53 |
-
target_columns = ""
|
| 54 |
-
|
| 55 |
-
|
| 56 |
scaler_inputs = unpickle_file(inference_dict["inference"]["scaler_inputs_path"])
|
| 57 |
scaler_targets = unpickle_file(inference_dict["inference"]["scaler_targets_path"])
|
| 58 |
encoder = unpickle_file(inference_dict["inference"]["encoder_path"])
|
|
@@ -67,6 +36,8 @@ def call_predict(inference_dict, cols_order):
|
|
| 67 |
df = pd.DataFrame([x_list], columns=cols_order)
|
| 68 |
print(df.shape)
|
| 69 |
|
|
|
|
|
|
|
| 70 |
|
| 71 |
y_pred, _, shap_values = predict(inference_dict["inference"]["model_path"], df_preprocessed, explainer)
|
| 72 |
|
|
|
|
| 14 |
# import time
|
| 15 |
# import cv2
|
| 16 |
# from prediction_coatings import predict
|
| 17 |
+
from utils import predict, unpickle_file, scale_numertical, encode_categorical
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
def call_predict(inference_dict, cols_order):
|
|
|
|
| 22 |
Encapsulates the predict function from utils to pass the config, and to put the data in the right format
|
| 23 |
"""
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
scaler_inputs = unpickle_file(inference_dict["inference"]["scaler_inputs_path"])
|
| 26 |
scaler_targets = unpickle_file(inference_dict["inference"]["scaler_targets_path"])
|
| 27 |
encoder = unpickle_file(inference_dict["inference"]["encoder_path"])
|
|
|
|
| 36 |
df = pd.DataFrame([x_list], columns=cols_order)
|
| 37 |
print(df.shape)
|
| 38 |
|
| 39 |
+
df_preprocessed = scale_numertical(df, numerical_columns, scaler=scaler_inputs, fit=False)
|
| 40 |
+
df_preprocessed = encode_categorical(df_preprocessed, categorical_columns, encoder=encoder, fit=False)
|
| 41 |
|
| 42 |
y_pred, _, shap_values = predict(inference_dict["inference"]["model_path"], df_preprocessed, explainer)
|
| 43 |
|