Spaces:
Sleeping
Sleeping
| 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']) | |