Spaces:
Sleeping
Sleeping
File size: 835 Bytes
e3c9101 |
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 |
import pandas as pd
from config import MODEL_PATH, TFIDF_PATH, TEXT_COLUMN, LABEL_COLUMNS
from utils import load_model_and_vectorizer
from schemas import TransactionData
def predict_labels(input_record: TransactionData):
# Load the model and vectorizer
model, vectorizer = load_model_and_vectorizer(MODEL_PATH, TFIDF_PATH)
# Convert input Pydantic model to DataFrame
input_data = pd.DataFrame([input_record.dict()])
# Prepare text input by selecting relevant fields
sanction_context = input_data[TEXT_COLUMN].iloc[0]
# Vectorize the input text
X_vec = vectorizer.transform([sanction_context])
# Predict labels
y_pred = model.predict(X_vec)
# Format predictions
predictions = {
LABEL_COLUMNS[i]: y_pred[0][i] for i in range(len(LABEL_COLUMNS))
}
return predictions
|