Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,12 +1,21 @@
|
|
1 |
-
from fastapi import FastAPI, HTTPException
|
2 |
from pydantic import BaseModel
|
3 |
-
from datasets import load_dataset
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# Load the datasets from the Hugging Face Hub
|
8 |
-
customers_dataset = load_dataset("dwb2023/
|
9 |
-
orders_dataset = load_dataset("dwb2023/
|
10 |
|
11 |
class GetUserInput(BaseModel):
|
12 |
key: str
|
@@ -55,7 +64,7 @@ def update_user(input: UpdateUserInput):
|
|
55 |
|
56 |
if user_found:
|
57 |
updated_dataset = Dataset.from_list(customers_data)
|
58 |
-
updated_dataset.push_to_hub("dwb2023/
|
59 |
customers_dataset = updated_dataset # Update the global dataset
|
60 |
return {"message": "User information updated successfully"}
|
61 |
else:
|
@@ -91,7 +100,7 @@ def cancel_order(input: CancelOrderInput):
|
|
91 |
|
92 |
if order_found:
|
93 |
updated_orders_dataset = Dataset.from_list(orders_data)
|
94 |
-
updated_orders_dataset.push_to_hub("dwb2023/
|
95 |
orders_dataset = updated_orders_dataset # Update the global dataset
|
96 |
return {"status": "Cancelled"}
|
97 |
else:
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException, Request
|
2 |
from pydantic import BaseModel
|
3 |
+
from datasets import load_dataset, Dataset
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
7 |
+
# Custom exception handler for better error visibility
|
8 |
+
@app.middleware("http")
|
9 |
+
async def add_process_time_header(request: Request, call_next):
|
10 |
+
try:
|
11 |
+
response = await call_next(request)
|
12 |
+
return response
|
13 |
+
except Exception as exc:
|
14 |
+
return JSONResponse(status_code=500, content={"message": str(exc)})
|
15 |
+
|
16 |
# Load the datasets from the Hugging Face Hub
|
17 |
+
customers_dataset = load_dataset("dwb2023/customers", split="train")
|
18 |
+
orders_dataset = load_dataset("dwb2023/orders", split="train")
|
19 |
|
20 |
class GetUserInput(BaseModel):
|
21 |
key: str
|
|
|
64 |
|
65 |
if user_found:
|
66 |
updated_dataset = Dataset.from_list(customers_data)
|
67 |
+
updated_dataset.push_to_hub("dwb2023/customers", split="train")
|
68 |
customers_dataset = updated_dataset # Update the global dataset
|
69 |
return {"message": "User information updated successfully"}
|
70 |
else:
|
|
|
100 |
|
101 |
if order_found:
|
102 |
updated_orders_dataset = Dataset.from_list(orders_data)
|
103 |
+
updated_orders_dataset.push_to_hub("dwb2023/orders", split="train")
|
104 |
orders_dataset = updated_orders_dataset # Update the global dataset
|
105 |
return {"status": "Cancelled"}
|
106 |
else:
|