Spaces:
Sleeping
Sleeping
| import random | |
| import os | |
| import csv | |
| from datetime import datetime | |
| def sample_pair(image_files): | |
| """Extract to random images""" | |
| return random.sample(image_files, 2) | |
| def save_score(img1, img2, score): | |
| """Save evaluation in CSV""" | |
| file_exists = os.path.isfile(SCORES_FILE) | |
| with open(SCORES_FILE, "a", newline="") as f: | |
| writer = csv.writer(f) | |
| if not file_exists: | |
| writer.writerow(["timestamp", "image_1", "image_2", "score"]) | |
| writer.writerow( | |
| [ | |
| datetime.utcnow().isoformat(), | |
| os.path.basename(img1), | |
| os.path.basename(img2), | |
| int(score), | |
| ] | |
| ) | |