Spaces:
Sleeping
Sleeping
Update model.py
Browse files
model.py
CHANGED
|
@@ -368,7 +368,7 @@ def retrain_model_with_feedback(user_id):
|
|
| 368 |
print("Retrained model saved.")
|
| 369 |
'''
|
| 370 |
|
| 371 |
-
|
| 372 |
def retrain_from_feedback(user_id: str):
|
| 373 |
"""Retrains model using feedback for a specific user and updates saved model + scaler."""
|
| 374 |
base_df = pd.read_csv(DATA_PATH)
|
|
@@ -398,7 +398,32 @@ def retrain_from_feedback(user_id: str):
|
|
| 398 |
print(f"✅ Model retrained and saved for user {user_id}")
|
| 399 |
return True
|
| 400 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
|
| 403 |
# ===============================
|
| 404 |
# 6. PREDICTION
|
|
|
|
| 368 |
print("Retrained model saved.")
|
| 369 |
'''
|
| 370 |
|
| 371 |
+
'''
|
| 372 |
def retrain_from_feedback(user_id: str):
|
| 373 |
"""Retrains model using feedback for a specific user and updates saved model + scaler."""
|
| 374 |
base_df = pd.read_csv(DATA_PATH)
|
|
|
|
| 398 |
print(f"✅ Model retrained and saved for user {user_id}")
|
| 399 |
return True
|
| 400 |
|
| 401 |
+
'''
|
| 402 |
+
def retrain_model_with_feedback(user_id):
|
| 403 |
+
base_df = pd.read_csv(DATA_PATH)
|
| 404 |
+
feedback_df = fetch_feedback_for_user(user_id)
|
| 405 |
+
if feedback_df.empty:
|
| 406 |
+
print("No feedback found for user:", user_id)
|
| 407 |
+
return {"message": f"No feedback found for user {user_id}"}
|
| 408 |
|
| 409 |
+
combined_df = pd.concat([base_df, feedback_df], ignore_index=True)
|
| 410 |
+
X, y1, y2, y3, scaler_obj = prepare_data(combined_df, combined_df['product'].unique().tolist())
|
| 411 |
+
model = build_model((X.shape[1], X.shape[2]))
|
| 412 |
+
model.fit(
|
| 413 |
+
X,
|
| 414 |
+
{'daily_consumption_output': y1,
|
| 415 |
+
'finish_error_output': y2,
|
| 416 |
+
'finish_days_output': y3},
|
| 417 |
+
epochs=10,
|
| 418 |
+
batch_size=32,
|
| 419 |
+
validation_split=0.1,
|
| 420 |
+
)
|
| 421 |
+
model.save(MODEL_PATH)
|
| 422 |
+
print("Retrained model saved.")
|
| 423 |
+
return {"message": f"Retraining complete for user {user_id}"}
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
|
| 427 |
|
| 428 |
# ===============================
|
| 429 |
# 6. PREDICTION
|