from fastapi import FastAPI, Query from fastapi.middleware.cors import CORSMiddleware 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("/") def root(): return {"status": "ok"} @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) return fig.to_dict()