Spaces:
Sleeping
Sleeping
Commit
·
8869031
1
Parent(s):
110c59a
adding files
Browse files
app.py
DELETED
|
@@ -1,7 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
|
| 3 |
-
app = FastAPI()
|
| 4 |
-
|
| 5 |
-
@app.get("/hello")
|
| 6 |
-
def hello():
|
| 7 |
-
return {"hello":"success"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, Form
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from google.cloud import storage
|
| 4 |
import io
|
|
@@ -65,22 +66,26 @@ async def upload_file(file: UploadFile = File(...)):
|
|
| 65 |
append_to_gcs_csv(df, gcs_file_path)
|
| 66 |
return {"message": "File uploaded successfully"}
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 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 |
@app.post("/clear-data/")
|
| 85 |
async def clear_data():
|
| 86 |
# Create an empty DataFrame with the same columns
|
|
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, Form
|
| 2 |
+
from fastapi import APIRouter, Depends, HTTPException, status
|
| 3 |
import pandas as pd
|
| 4 |
from google.cloud import storage
|
| 5 |
import io
|
|
|
|
| 66 |
append_to_gcs_csv(df, gcs_file_path)
|
| 67 |
return {"message": "File uploaded successfully"}
|
| 68 |
|
| 69 |
+
@app.post("/upload-data/")
|
| 70 |
+
async def upload_data(category: str = Form(...), score: float = Form(...)):
|
| 71 |
+
df = pd.DataFrame([[category, score]], columns=['category', 'score'])
|
| 72 |
+
append_to_gcs_csv(df, gcs_file_path)
|
| 73 |
+
return {"message": "Data uploaded successfully"}
|
| 74 |
|
| 75 |
+
@app.post("/upload-data-raw/")
|
| 76 |
+
async def upload_data_raw(payload: dict):
|
| 77 |
+
# sourcery skip: raise-from-previous-error
|
| 78 |
+
try:
|
| 79 |
+
category = payload['category']
|
| 80 |
+
score = payload['score']
|
| 81 |
+
except KeyError:
|
| 82 |
+
raise HTTPException(status_code=400, detail="Invalid payload format")
|
| 83 |
|
| 84 |
+
df = pd.DataFrame([[category, score]], columns=['category', 'score'])
|
|
|
|
|
|
|
| 85 |
append_to_gcs_csv(df, gcs_file_path)
|
| 86 |
return {"message": "Data uploaded successfully"}
|
| 87 |
|
| 88 |
+
|
| 89 |
@app.post("/clear-data/")
|
| 90 |
async def clear_data():
|
| 91 |
# Create an empty DataFrame with the same columns
|