kandi1clickkits commited on
Commit
8557221
·
1 Parent(s): aafbd27

chart code

Browse files
Files changed (2) hide show
  1. main.py +22 -4
  2. requirements.txt +1 -0
main.py CHANGED
@@ -1,6 +1,24 @@
1
- from fastapi import FastAPI
 
 
2
  app = FastAPI()
3
 
4
- @app.get("/hello")
5
- def hello():
6
- return {"hello":"you success deploy"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException, Body
2
+ import pandas as pd
3
+
4
  app = FastAPI()
5
 
6
+ def process_json(input_data: dict):
7
+ try:
8
+ # Assuming the input_data is a dictionary with keys representing columns and values as lists
9
+ df = pd.DataFrame(input_data)
10
+ except Exception as e:
11
+ raise HTTPException(status_code=400, detail=f"Error processing input data: {str(e)}")
12
+
13
+ # Customize this part based on your specific charting requirements
14
+ # For example, you can return a dictionary with keys for x-axis and y-axis data
15
+ chart_data = {
16
+ "x_axis": df.columns.tolist(),
17
+ "y_axis": df.values.tolist()
18
+ }
19
+
20
+ return chart_data
21
+
22
+ @app.post("/create-chart")
23
+ async def create_chart(input_data: dict = Body(...)):
24
+ return process_json(input_data)
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  fastapi
2
  uvicorn
 
 
1
  fastapi
2
  uvicorn
3
+ pandas