Spaces:
Sleeping
Sleeping
Manveer commited on
Commit ยท
3c9596b
1
Parent(s): 1541b6c
Add application file 10
Browse files
app.py
CHANGED
|
@@ -174,18 +174,35 @@ def process_po(po_df, sku_df):
|
|
| 174 |
async def predict_batch(request: POBatchRequest):
|
| 175 |
try:
|
| 176 |
po_df = pd.DataFrame([item.dict() for item in request.items])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
processed_df = process_po(po_df, sku_df)
|
|
|
|
|
|
|
| 178 |
response = processed_df[[
|
| 179 |
"Product_Name", "predicted_risk_label", "missing_field_score_v2",
|
| 180 |
"semantic_signal", "delivery_lag_flag", "description_token_rarity_score",
|
| 181 |
"filename_type_encoded"
|
| 182 |
]].copy()
|
| 183 |
response["poid"] = processed_df.get("POID", "")
|
|
|
|
|
|
|
| 184 |
data = response.rename(columns={"Product_Name": "product_name"}).to_dict(orient="records")
|
|
|
|
| 185 |
return {"data": data}
|
|
|
|
| 186 |
except Exception as e:
|
| 187 |
logger.error(f"Prediction failed: {e}")
|
| 188 |
raise HTTPException(status_code=500, detail=str(e))
|
| 189 |
|
|
|
|
| 190 |
if __name__ == "__main__":
|
| 191 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 174 |
async def predict_batch(request: POBatchRequest):
|
| 175 |
try:
|
| 176 |
po_df = pd.DataFrame([item.dict() for item in request.items])
|
| 177 |
+
|
| 178 |
+
# ๐ง Rename fields to match what process_po() expects
|
| 179 |
+
po_df.rename(columns={
|
| 180 |
+
"product_name": "Product_Name",
|
| 181 |
+
"quantity": "Quantity",
|
| 182 |
+
"delivery_date": "Delivery_Date",
|
| 183 |
+
"filename": "Filename",
|
| 184 |
+
"company_name": "Company_Name"
|
| 185 |
+
}, inplace=True)
|
| 186 |
+
|
| 187 |
processed_df = process_po(po_df, sku_df)
|
| 188 |
+
|
| 189 |
+
# ๐ Prepare response using updated column names
|
| 190 |
response = processed_df[[
|
| 191 |
"Product_Name", "predicted_risk_label", "missing_field_score_v2",
|
| 192 |
"semantic_signal", "delivery_lag_flag", "description_token_rarity_score",
|
| 193 |
"filename_type_encoded"
|
| 194 |
]].copy()
|
| 195 |
response["poid"] = processed_df.get("POID", "")
|
| 196 |
+
|
| 197 |
+
# ๐ Convert to JSON format with camelCase keys
|
| 198 |
data = response.rename(columns={"Product_Name": "product_name"}).to_dict(orient="records")
|
| 199 |
+
|
| 200 |
return {"data": data}
|
| 201 |
+
|
| 202 |
except Exception as e:
|
| 203 |
logger.error(f"Prediction failed: {e}")
|
| 204 |
raise HTTPException(status_code=500, detail=str(e))
|
| 205 |
|
| 206 |
+
|
| 207 |
if __name__ == "__main__":
|
| 208 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|