|
import joblib
|
|
import numpy as np
|
|
|
|
|
|
try:
|
|
with open('vectorizer.pkl', 'rb') as f:
|
|
vectorizer = joblib.load(f)
|
|
except Exception as e:
|
|
print(f"Error al cargar el vectorizador: {e}")
|
|
|
|
|
|
try:
|
|
with open('model.pkl', 'rb') as f:
|
|
model = joblib.load(f)
|
|
except Exception as e:
|
|
print(f"Error al cargar el modelo: {e}")
|
|
|
|
def preprocess(text):
|
|
"""Preprocesa el texto para la inferencia."""
|
|
try:
|
|
return vectorizer.transform([text])
|
|
except Exception as e:
|
|
print(f"Error en el preprocesamiento: {e}")
|
|
|
|
def predict(text):
|
|
"""Realiza la predicci贸n a partir del texto ingresado."""
|
|
try:
|
|
X = preprocess(text)
|
|
return model.predict(X)
|
|
except Exception as e:
|
|
print(f"Error en la predicci贸n: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_text = "Texto de prueba para predecir"
|
|
result = predict(test_text)
|
|
print(f"Predicci贸n: {result}")
|
|
|