Spaces:
Sleeping
Sleeping
File size: 1,240 Bytes
508f06f | 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 | import json
import pandas as pd
import os
from typing import List, Dict
EXAMPLES_FILE = os.path.join(os.path.dirname(__file__), '../data/examples.json')
LEADERBOARD_FILE = os.path.join(os.path.dirname(__file__), '../data/leaderboard.csv')
def load_examples() -> List[Dict[str, str]]:
"""Loads few-shot examples from the JSON file."""
try:
with open(EXAMPLES_FILE, 'r') as f:
return json.load(f)
except FileNotFoundError:
return []
def update_leaderboard(winner: str, query: str):
"""Updates the leaderboard CSV with the latest win."""
if not os.path.exists(LEADERBOARD_FILE):
df = pd.DataFrame(columns=['Timestamp', 'Winner', 'Query'])
else:
df = pd.read_csv(LEADERBOARD_FILE)
new_entry = {
'Timestamp': pd.Timestamp.now(),
'Winner': winner,
'Query': query
}
df = pd.concat([df, pd.DataFrame([new_entry])], ignore_index=True)
df.to_csv(LEADERBOARD_FILE, index=False)
def get_leaderboard():
"""Returns the leaderboard DataFrame."""
if os.path.exists(LEADERBOARD_FILE):
return pd.read_csv(LEADERBOARD_FILE)
return pd.DataFrame(columns=['Timestamp', 'Winner', 'Query'])
|