dwb2023 commited on
Commit
73821b2
1 Parent(s): 8067a56

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -8
main.py CHANGED
@@ -5,8 +5,8 @@ from datasets import load_dataset
5
  app = FastAPI()
6
 
7
  # Load the datasets from the Hugging Face Hub
8
- customers_dataset = load_dataset("dwb2023/customers")["train"]
9
- orders_dataset = load_dataset("dwb2023/orders")["train"]
10
 
11
  class GetUserInput(BaseModel):
12
  key: str
@@ -43,7 +43,7 @@ def update_user(input: UpdateUserInput):
43
  global customers_dataset
44
  customers_data = customers_dataset.to_list()
45
  user_found = False
46
-
47
  for customer in customers_data:
48
  if customer["id"] == input.user_id:
49
  if input.email:
@@ -52,10 +52,10 @@ def update_user(input: UpdateUserInput):
52
  customer["phone"] = input.phone
53
  user_found = True
54
  break
55
-
56
  if user_found:
57
  updated_dataset = Dataset.from_list(customers_data)
58
- updated_dataset.push_to_hub("dwb2023/customers", split="train")
59
  customers_dataset = updated_dataset # Update the global dataset
60
  return {"message": "User information updated successfully"}
61
  else:
@@ -79,7 +79,7 @@ def cancel_order(input: CancelOrderInput):
79
  global orders_dataset
80
  orders_data = orders_dataset.to_list()
81
  order_found = False
82
-
83
  for order in orders_data:
84
  if order["id"] == input.order_id:
85
  if order["status"] == "Processing":
@@ -88,10 +88,10 @@ def cancel_order(input: CancelOrderInput):
88
  break
89
  else:
90
  raise HTTPException(status_code=400, detail="Order has already shipped. Can't cancel it.")
91
-
92
  if order_found:
93
  updated_orders_dataset = Dataset.from_list(orders_data)
94
- updated_orders_dataset.push_to_hub("dwb2023/orders", split="train")
95
  orders_dataset = updated_orders_dataset # Update the global dataset
96
  return {"status": "Cancelled"}
97
  else:
 
5
  app = FastAPI()
6
 
7
  # Load the datasets from the Hugging Face Hub
8
+ customers_dataset = load_dataset("dwb2023/blackbird-customers", split="train")
9
+ orders_dataset = load_dataset("dwb2023/blackbird-orders", split="train")
10
 
11
  class GetUserInput(BaseModel):
12
  key: str
 
43
  global customers_dataset
44
  customers_data = customers_dataset.to_list()
45
  user_found = False
46
+
47
  for customer in customers_data:
48
  if customer["id"] == input.user_id:
49
  if input.email:
 
52
  customer["phone"] = input.phone
53
  user_found = True
54
  break
55
+
56
  if user_found:
57
  updated_dataset = Dataset.from_list(customers_data)
58
+ updated_dataset.push_to_hub("dwb2023/blackbird-customers", split="train")
59
  customers_dataset = updated_dataset # Update the global dataset
60
  return {"message": "User information updated successfully"}
61
  else:
 
79
  global orders_dataset
80
  orders_data = orders_dataset.to_list()
81
  order_found = False
82
+
83
  for order in orders_data:
84
  if order["id"] == input.order_id:
85
  if order["status"] == "Processing":
 
88
  break
89
  else:
90
  raise HTTPException(status_code=400, detail="Order has already shipped. Can't cancel it.")
91
+
92
  if order_found:
93
  updated_orders_dataset = Dataset.from_list(orders_data)
94
+ updated_orders_dataset.push_to_hub("dwb2023/blackbird-orders", split="train")
95
  orders_dataset = updated_orders_dataset # Update the global dataset
96
  return {"status": "Cancelled"}
97
  else: