navitrace_leaderboard / src /api_server.py
TimWindecker's picture
Update src/api_server.py
66f871b verified
raw
history blame contribute delete
685 Bytes
from fastapi import FastAPI, Query
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import plotly.io as pio
from src.streamlit_app import load_data, create_bar_chart
api = FastAPI(title="Leaderboard API")
api.add_middleware(
CORSMiddleware,
allow_origins=["https://leggedrobotics.github.io"],
allow_methods=["*"],
allow_headers=["*"],
)
@api.get("/chart")
def get_chart(view: str = Query("Total Score", description="Chart type")):
"""Return chart JSON for the given view type."""
df = load_data()
fig = create_bar_chart(df, view)
fig_json = pio.to_json(fig)
return JSONResponse(content=fig_json)