Spaces:
Sleeping
Sleeping
| import csv | |
| import os | |
| from datetime import datetime | |
| LOG_FILE = "feedback_log.csv" | |
| def log_feedback( | |
| question, | |
| option1, | |
| option2, | |
| context, | |
| evo_output, | |
| gpt_output, | |
| evo_reasoning, | |
| user_preference=None | |
| ): | |
| """ | |
| Logs Evo and GPT output along with user's preference for retraining. | |
| Creates feedback_log.csv automatically if it doesn't exist. | |
| """ | |
| print("✅ log_feedback() triggered") | |
| print("User voted:", user_preference) | |
| file_exists = os.path.isfile(LOG_FILE) | |
| try: | |
| with open(LOG_FILE, mode='a', newline='', encoding='utf-8') as file: | |
| writer = csv.writer(file) | |
| if not file_exists: | |
| writer.writerow([ | |
| "timestamp", | |
| "question", | |
| "option1", | |
| "option2", | |
| "context", | |
| "evo_output", | |
| "gpt_output", | |
| "evo_reasoning", | |
| "user_preference", | |
| "evo_was_correct" | |
| ]) | |
| evo_was_correct = "yes" if user_preference == "Evo" else ( | |
| "no" if user_preference == "GPT" else "" | |
| ) | |
| writer.writerow([ | |
| datetime.now().isoformat(), | |
| question, | |
| option1, | |
| option2, | |
| context, | |
| evo_output, | |
| gpt_output, | |
| evo_reasoning, | |
| user_preference or "", | |
| evo_was_correct | |
| ]) | |
| print("✅ Feedback successfully logged.") | |
| except Exception as e: | |
| print("❌ Failed to log feedback:", e) | |
| # ✅ Manual test trigger | |
| if __name__ == "__main__": | |
| log_feedback( | |
| "What is 2 + 2?", | |
| "4", | |
| "5", | |
| "Basic math context", | |
| "4", | |
| "4", | |
| "Both answered correctly.", | |
| "Evo" | |
| ) | |