File size: 685 Bytes
371bcb5 baa5547 66f871b 371bcb5 baa5547 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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)
|