Spaces:
Configuration error
Configuration error
celpri commited on
Commit ·
5a96a2a
1
Parent(s): 717c00a
Fix: final model loading with token and correct repo id
Browse files- src/model/model.py +16 -6
src/model/model.py
CHANGED
|
@@ -3,16 +3,26 @@ from pathlib import Path
|
|
| 3 |
import os
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def load_model():
|
| 7 |
-
# --- STRATÉGIE 1 : Hugging Face Space ---
|
| 8 |
-
# On essaie de télécharger le modèle depuis ton dépôt de modèles HF
|
| 9 |
try:
|
| 10 |
-
#
|
| 11 |
-
model_path = hf_hub_download(
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return joblib.load(model_path)
|
| 14 |
except Exception as e:
|
| 15 |
-
print(f"Échec
|
|
|
|
| 16 |
|
| 17 |
# --- STRATÉGIE 2 : MLflow (Local uniquement) ---
|
| 18 |
# Si on est chez toi, on utilise MLflow
|
|
|
|
| 3 |
import os
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
+
import os
|
| 7 |
+
from huggingface_hub import hf_hub_download
|
| 8 |
+
import joblib
|
| 9 |
+
|
| 10 |
+
# On récupère le token que tu vas créer dans les réglages du Space
|
| 11 |
+
token = os.environ.get("HF_TOKEN")
|
| 12 |
+
|
| 13 |
def load_model():
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
+
# On pointe vers le bon dépôt de modèle (pas le space)
|
| 16 |
+
model_path = hf_hub_download(
|
| 17 |
+
repo_id="PCelia/credit-scoring-model",
|
| 18 |
+
filename="model.joblib",
|
| 19 |
+
token=token
|
| 20 |
+
)
|
| 21 |
+
print("Modèle chargé avec succès depuis le Hub !")
|
| 22 |
return joblib.load(model_path)
|
| 23 |
except Exception as e:
|
| 24 |
+
print(f"Échec HF Hub: {e}")
|
| 25 |
+
|
| 26 |
|
| 27 |
# --- STRATÉGIE 2 : MLflow (Local uniquement) ---
|
| 28 |
# Si on est chez toi, on utilise MLflow
|