import json import os import time from collections import defaultdict from functools import lru_cache import argilla as rg import gradio as gr import pandas as pd from dotenv import load_dotenv from fastapi import FastAPI from calculate_personal_scores import calculate_personal_scores from calculate_team_scores import calculate_team_scores load_dotenv() # FastAPI app app = FastAPI() # Global variables for caching last_update_time = 0 cached_data = None def create_leaderboard_ui(): """Create the leaderboard UI with caching.""" global cached_data, last_update_time current_time = time.time() if cached_data is not None and current_time - last_update_time < 300: df = cached_data else: print("Recalculating scores...") df = calculate_personal_scores() cached_data = df last_update_time = current_time calculate_team_scores() if not df.empty: df = df.reset_index(drop=True) df.index = df.index + 1 df = df.rename_axis("Rank").reset_index() df_html = df.to_html(classes="leaderboard-table", border=0, index=False) return f"""
Última Actualización: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(last_update_time))}
{df_html}