TimWindecker commited on
Commit
baa5547
·
verified ·
1 Parent(s): ed96df8

Update src/api_server.py

Browse files
Files changed (1) hide show
  1. src/api_server.py +4 -5
src/api_server.py CHANGED
@@ -1,5 +1,7 @@
1
  from fastapi import FastAPI, Query
2
  from fastapi.middleware.cors import CORSMiddleware
 
 
3
  from src.streamlit_app import load_data, create_bar_chart
4
 
5
  api = FastAPI(title="Leaderboard API")
@@ -11,14 +13,11 @@ api.add_middleware(
11
  allow_headers=["*"],
12
  )
13
 
14
- # @api.get("/")
15
- # def root():
16
- # return {"status": "ok"}
17
-
18
  @api.get("/chart")
19
  def get_chart(view: str = Query("Total Score", description="Chart type")):
20
  """Return chart JSON for the given view type."""
21
 
22
  df = load_data()
23
  fig = create_bar_chart(df, view)
24
- return fig.to_dict()
 
 
1
  from fastapi import FastAPI, Query
2
  from fastapi.middleware.cors import CORSMiddleware
3
+ from fastapi.responses import JSONResponse
4
+ import plotly.io as pio
5
  from src.streamlit_app import load_data, create_bar_chart
6
 
7
  api = FastAPI(title="Leaderboard API")
 
13
  allow_headers=["*"],
14
  )
15
 
 
 
 
 
16
  @api.get("/chart")
17
  def get_chart(view: str = Query("Total Score", description="Chart type")):
18
  """Return chart JSON for the given view type."""
19
 
20
  df = load_data()
21
  fig = create_bar_chart(df, view)
22
+ fig_json = pio.to_json(fig)
23
+ return JSONResponse(content=fig_json)