Spaces:
Sleeping
Sleeping
File size: 1,598 Bytes
b0e670a |
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 41 42 |
import csv
import os
from datetime import datetime
from retrain_from_feedback import train_evo
# π Main entry point for feedback-triggered retraining
def retrain_from_feedback(feedback_log):
# β
Check if feedback is present
if not feedback_log:
return "β οΈ No feedback data to retrain from."
# π Write feedback to CSV
try:
os.makedirs("feedback", exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filepath = f"feedback/feedback_log.csv" # also usable for loading
with open(filepath, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow([
"question", "option1", "option2", "answer",
"confidence", "reasoning", "context",
"user_preference", "evo_was_correct", "evo_output"
])
for row in feedback_log:
question, option1, option2, answer, confidence, reasoning, context = row
# Simulate Evo being preferred (you can modify this logic later)
writer.writerow([
question, option1, option2, answer,
confidence, reasoning, context,
"evo", "yes", answer
])
except Exception as e:
return f"β Failed to save feedback: {str(e)}"
# π Trigger training
try:
train_evo() # This uses the latest feedback_log.csv
return "β
Evo retrained and weights saved."
except Exception as e:
return f"β Evo training failed: {str(e)}"
|