deepak6593 commited on
Commit
5b319d9
·
1 Parent(s): a9fe782

adding files

Browse files
Files changed (2) hide show
  1. main.py +15 -2
  2. requirements.txt +0 -1
main.py CHANGED
@@ -4,6 +4,7 @@ from google.cloud import storage
4
  import io
5
  import os
6
  import tempfile
 
7
 
8
  app = FastAPI()
9
 
@@ -64,12 +65,24 @@ async def upload_file(file: UploadFile = File(...)):
64
  append_to_gcs_csv(df, gcs_file_path)
65
  return {"message": "File uploaded successfully"}
66
 
 
 
 
 
 
 
 
 
 
 
67
  @app.post("/upload-data/")
68
- async def upload_data(category: str = Form(...), score: float = Form(...)):
69
- df = pd.DataFrame([[category, score]], columns=['category', 'score'])
70
  append_to_gcs_csv(df, gcs_file_path)
71
  return {"message": "Data uploaded successfully"}
72
 
 
 
73
  @app.post("/clear-data/")
74
  async def clear_data():
75
  # Create an empty DataFrame with the same columns
 
4
  import io
5
  import os
6
  import tempfile
7
+ from pydantic import BaseModel
8
 
9
  app = FastAPI()
10
 
 
65
  append_to_gcs_csv(df, gcs_file_path)
66
  return {"message": "File uploaded successfully"}
67
 
68
+ # @app.post("/upload-data/")
69
+ # async def upload_data(category: str = Form(...), score: float = Form(...)):
70
+ # df = pd.DataFrame([[category, score]], columns=['category', 'score'])
71
+ # append_to_gcs_csv(df, gcs_file_path)
72
+ # return {"message": "Data uploaded successfully"}
73
+
74
+ class DataPayload(BaseModel):
75
+ category: str
76
+ score: float
77
+
78
  @app.post("/upload-data/")
79
+ async def upload_data(payload: DataPayload):
80
+ df = pd.DataFrame([[payload.category, payload.score]], columns=['category', 'score'])
81
  append_to_gcs_csv(df, gcs_file_path)
82
  return {"message": "Data uploaded successfully"}
83
 
84
+
85
+
86
  @app.post("/clear-data/")
87
  async def clear_data():
88
  # Create an empty DataFrame with the same columns
requirements.txt CHANGED
@@ -2,5 +2,4 @@ fastapi
2
  uvicorn
3
  pandas
4
  gradio
5
- sqlalchemy
6
  google-cloud-storage
 
2
  uvicorn
3
  pandas
4
  gradio
 
5
  google-cloud-storage