Spaces:
Runtime error
Runtime error
Aurélie GABU
commited on
Commit
·
2df3397
1
Parent(s):
d404857
deactivating DB from predict in git actions
Browse files- App/predict.py +18 -17
App/predict.py
CHANGED
|
@@ -46,26 +46,27 @@ def predict_employee(data: dict):
|
|
| 46 |
pred = model.predict(df)[0]
|
| 47 |
proba = model.predict_proba(df)[0][1]
|
| 48 |
|
| 49 |
-
db: Session = SessionLocal()
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
# puis on renvoie la réponse API
|
| 71 |
return {
|
|
|
|
| 46 |
pred = model.predict(df)[0]
|
| 47 |
proba = model.predict_proba(df)[0][1]
|
| 48 |
|
| 49 |
+
db: Session = SessionLocal() if SessionLocal is not None else None
|
| 50 |
|
| 51 |
+
if db is not None:
|
| 52 |
+
try:
|
| 53 |
+
# enregistrer les inputs: à chaque appel de POST/predict, on stocke d'abord les entrées de l'utilisateur
|
| 54 |
+
input_row = Input(**data)
|
| 55 |
+
db.add(input_row)
|
| 56 |
+
db.commit()
|
| 57 |
+
db.refresh(input_row)
|
| 58 |
|
| 59 |
+
# puis on récupère les ids générés automatiquement et enregistre les prédictions liés aux ids
|
| 60 |
+
pred_row = Predictions(input_id = input_row.id, prediction_label = classes_mapping[str(pred)], prediction_proba = float(proba), model_version = "v1")
|
| 61 |
+
db.add(pred_row)
|
| 62 |
+
db.commit()
|
| 63 |
+
|
| 64 |
+
except Exception as e:
|
| 65 |
+
print("🔥 ERREUR DB :", e)
|
| 66 |
+
raise e
|
| 67 |
|
| 68 |
+
finally:
|
| 69 |
+
db.close()
|
| 70 |
|
| 71 |
# puis on renvoie la réponse API
|
| 72 |
return {
|