Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -376,54 +376,55 @@ def inventory_report(question):
|
|
| 376 |
# Extracting the id for the warehouse with the name "WH"
|
| 377 |
warehouse_id = next((item['id'] for item in data['result'] if item['name'] == warehouse_name), None)
|
| 378 |
#print(warehouse_id)
|
| 379 |
-
if warehouse_id
|
| 380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
return "Please provide a warehouse name available in the database."
|
| 382 |
-
# print(f"The id for the warehouse named {name} is: {warehouse_id}")
|
| 383 |
-
# Step 3: Update the placeholder with the actual warehouse_id
|
| 384 |
-
for api in apis:
|
| 385 |
-
if "warehouseId" in api["params"]:
|
| 386 |
-
api["params"]["warehouseId"] = warehouse_id
|
| 387 |
-
|
| 388 |
-
print(f"warehouseId: {warehouse_id}")
|
| 389 |
-
print(f"warehouseId: {apis[1]}")
|
| 390 |
-
|
| 391 |
-
data1 = make_api_request(apis[1]["url"], apis[1]["params"])
|
| 392 |
-
if (data1):
|
| 393 |
-
headers = ["S.No", "Warehouse Code", "Warehouse Name", "Customer Code", "Customer Name", "Item Code", "Item Name",
|
| 394 |
-
"Currency", "EAN", "UOM", "Quantity", "Gross Weight", "Volume", "Total Value"]
|
| 395 |
-
table_data = []
|
| 396 |
-
|
| 397 |
-
for index, item in enumerate(data1['result'], start=1):
|
| 398 |
-
row = [
|
| 399 |
-
index, # Serial number
|
| 400 |
-
item['warehouse']['code'],
|
| 401 |
-
item['warehouse']['name'],
|
| 402 |
-
item['customer']['code'],
|
| 403 |
-
item['customer']['name'],
|
| 404 |
-
item['skuMaster']['code'],
|
| 405 |
-
item['skuMaster']['name'],
|
| 406 |
-
item['currency']['code'],
|
| 407 |
-
item['eanUpc'],
|
| 408 |
-
item['uom']['code'],
|
| 409 |
-
item['totalQty'],
|
| 410 |
-
item['grossWeight'],
|
| 411 |
-
item['volume'],
|
| 412 |
-
item['totalValue']
|
| 413 |
-
]
|
| 414 |
-
table_data.append(row)
|
| 415 |
-
|
| 416 |
-
# Convert to pandas DataFrame
|
| 417 |
-
df = pd.DataFrame(table_data, columns=headers)
|
| 418 |
-
|
| 419 |
-
sdf = SmartDataframe(df, config={"llm": llm_chart})
|
| 420 |
-
|
| 421 |
-
# chart = sdf.chat("Can you draw a bar chart with all avaialble item name and quantity.")
|
| 422 |
-
chart = sdf.chat(question)
|
| 423 |
-
|
| 424 |
-
return chart
|
| 425 |
-
else:
|
| 426 |
-
return "There are no inventory details for the warehouse you have given."
|
| 427 |
|
| 428 |
|
| 429 |
# inventory_report("WH:can you give me a bar chart with item name and quantity for the warehouse WH")
|
|
|
|
| 376 |
# Extracting the id for the warehouse with the name "WH"
|
| 377 |
warehouse_id = next((item['id'] for item in data['result'] if item['name'] == warehouse_name), None)
|
| 378 |
#print(warehouse_id)
|
| 379 |
+
if (warehouse_id):
|
| 380 |
+
|
| 381 |
+
# print(f"The id for the warehouse named {name} is: {warehouse_id}")
|
| 382 |
+
# Step 3: Update the placeholder with the actual warehouse_id
|
| 383 |
+
for api in apis:
|
| 384 |
+
if "warehouseId" in api["params"]:
|
| 385 |
+
api["params"]["warehouseId"] = warehouse_id
|
| 386 |
+
|
| 387 |
+
print(f"warehouseId: {warehouse_id}")
|
| 388 |
+
print(f"warehouseId: {apis[1]}")
|
| 389 |
+
|
| 390 |
+
data1 = make_api_request(apis[1]["url"], apis[1]["params"])
|
| 391 |
+
if (data1):
|
| 392 |
+
headers = ["S.No", "Warehouse Code", "Warehouse Name", "Customer Code", "Customer Name", "Item Code", "Item Name",
|
| 393 |
+
"Currency", "EAN", "UOM", "Quantity", "Gross Weight", "Volume", "Total Value"]
|
| 394 |
+
table_data = []
|
| 395 |
+
|
| 396 |
+
for index, item in enumerate(data1['result'], start=1):
|
| 397 |
+
row = [
|
| 398 |
+
index, # Serial number
|
| 399 |
+
item['warehouse']['code'],
|
| 400 |
+
item['warehouse']['name'],
|
| 401 |
+
item['customer']['code'],
|
| 402 |
+
item['customer']['name'],
|
| 403 |
+
item['skuMaster']['code'],
|
| 404 |
+
item['skuMaster']['name'],
|
| 405 |
+
item['currency']['code'],
|
| 406 |
+
item['eanUpc'],
|
| 407 |
+
item['uom']['code'],
|
| 408 |
+
item['totalQty'],
|
| 409 |
+
item['grossWeight'],
|
| 410 |
+
item['volume'],
|
| 411 |
+
item['totalValue']
|
| 412 |
+
]
|
| 413 |
+
table_data.append(row)
|
| 414 |
+
|
| 415 |
+
# Convert to pandas DataFrame
|
| 416 |
+
df = pd.DataFrame(table_data, columns=headers)
|
| 417 |
+
|
| 418 |
+
sdf = SmartDataframe(df, config={"llm": llm_chart})
|
| 419 |
+
|
| 420 |
+
# chart = sdf.chat("Can you draw a bar chart with all avaialble item name and quantity.")
|
| 421 |
+
chart = sdf.chat(question)
|
| 422 |
+
|
| 423 |
+
return chart
|
| 424 |
+
else:
|
| 425 |
+
return "There are no inventory details for the warehouse you have given."
|
| 426 |
+
else:
|
| 427 |
return "Please provide a warehouse name available in the database."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
|
| 429 |
|
| 430 |
# inventory_report("WH:can you give me a bar chart with item name and quantity for the warehouse WH")
|