Spaces:
Sleeping
Sleeping
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)}" | |