File size: 1,164 Bytes
2ac8a57 |
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 31 32 33 34 35 36 37 38 39 40 |
"""
Script de chargement pour le modèle logistic regression
"""
import pickle
import numpy as np
from huggingface_hub import hf_hub_download
def load_logistic_model(repo_id="Carlito-25/sentiment-model-logistic"):
"""Charge le modèle logistic regression depuis Hugging Face"""
model_path = hf_hub_download(
repo_id=repo_id,
filename="model.pkl"
)
with open(model_path, 'rb') as f:
model = pickle.load(f)
return model
def predict_sentiment(model, text_features):
"""Prédiction avec le modèle logistic regression"""
if isinstance(text_features, list):
text_features = np.array(text_features).reshape(1, -1)
prediction = model.predict(text_features)
probabilities = model.predict_proba(text_features)
return {
'prediction': prediction[0],
'probabilities': probabilities[0].tolist()
}
# Exemple d'usage
if __name__ == "__main__":
model = load_logistic_model()
# Remplace par tes features réelles
dummy_features = np.random.rand(1, 100) # Adapte selon tes features
result = predict_sentiment(model, dummy_features)
print(result)
|