|
import httpx |
|
import pandas as pd |
|
from typing import Optional, Dict |
|
import streamlit as st |
|
from src.core.config import settings |
|
|
|
async def fetch_leaderboard_data( |
|
model_name: Optional[str] = None, |
|
benchmark_label: Optional[str] = None |
|
) -> pd.DataFrame: |
|
"""Fetch and process leaderboard data""" |
|
params = {} |
|
if model_name and model_name != "All": |
|
params["model_name"] = model_name |
|
if benchmark_label and benchmark_label != "All": |
|
params["benchmark_label"] = benchmark_label |
|
|
|
headers = { |
|
"Authorization": f"Bearer {settings.HF_TOKEN}", |
|
"Accept": "application/json" |
|
} |
|
|
|
try: |
|
async with httpx.AsyncClient() as client: |
|
response = await client.get( |
|
f"{settings.API_URL}/api/v1/leaderboard", |
|
params=params, |
|
headers=headers, |
|
follow_redirects=True |
|
) |
|
response.raise_for_status() |
|
data = response.json() |
|
return pd.DataFrame(data) |
|
except Exception as e: |
|
st.error(f"Error fetching data: {str(e)}") |
|
if hasattr(e, 'response'): |
|
st.error(f"Response: {e.response.text}") |
|
return pd.DataFrame() |