Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -7,8 +7,8 @@ import joblib
|
|
| 7 |
|
| 8 |
|
| 9 |
# Load your trained model and encoders
|
| 10 |
-
xgb_model = joblib.load("model/
|
| 11 |
-
encoders = joblib.load("model/
|
| 12 |
|
| 13 |
# Function to handle unseen labels during encoding
|
| 14 |
def safe_transform(encoder, column):
|
|
@@ -33,18 +33,22 @@ def predict(
|
|
| 33 |
customer_phone: str,
|
| 34 |
customer_email: str,
|
| 35 |
weight: str,
|
|
|
|
| 36 |
pickup_address: str,
|
| 37 |
destination_city_name: str):
|
| 38 |
# Convert input data to DataFrame
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
input_data = {
|
| 40 |
'customer_name': customer_name,
|
| 41 |
'customer_address': customer_address,
|
| 42 |
'customer_phone': customer_phone,
|
| 43 |
'customer_email': customer_email,
|
| 44 |
-
'cod':
|
| 45 |
'weight': float(weight),
|
| 46 |
'pickup_address':pickup_address,
|
| 47 |
-
'origin_city.name':"origin_city_name",
|
| 48 |
'destination_city.name':destination_city_name
|
| 49 |
}
|
| 50 |
input_df = pd.DataFrame([input_data])
|
|
@@ -62,7 +66,7 @@ def predict(
|
|
| 62 |
predicted_status = "Unknown" if pred[0] == -1 else encoders['status.name'].inverse_transform([pred])[0]
|
| 63 |
probability = pred_proba[0][pred[0]] * 100 if pred[0] != -1 else "Unknown"
|
| 64 |
|
| 65 |
-
if predicted_status == "
|
| 66 |
probability = 100 - probability
|
| 67 |
|
| 68 |
return {"Probability": round(probability,2)}
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
# Load your trained model and encoders
|
| 10 |
+
xgb_model = joblib.load("model/transexpress_xgb_model.joblib")
|
| 11 |
+
encoders = joblib.load("model/transexpress_encoders.joblib")
|
| 12 |
|
| 13 |
# Function to handle unseen labels during encoding
|
| 14 |
def safe_transform(encoder, column):
|
|
|
|
| 33 |
customer_phone: str,
|
| 34 |
customer_email: str,
|
| 35 |
weight: str,
|
| 36 |
+
cod:str,
|
| 37 |
pickup_address: str,
|
| 38 |
destination_city_name: str):
|
| 39 |
# Convert input data to DataFrame
|
| 40 |
+
|
| 41 |
+
if destination_city_name=="":
|
| 42 |
+
destination_city_name = 'Missing'
|
| 43 |
+
|
| 44 |
input_data = {
|
| 45 |
'customer_name': customer_name,
|
| 46 |
'customer_address': customer_address,
|
| 47 |
'customer_phone': customer_phone,
|
| 48 |
'customer_email': customer_email,
|
| 49 |
+
'cod': float(cod),
|
| 50 |
'weight': float(weight),
|
| 51 |
'pickup_address':pickup_address,
|
|
|
|
| 52 |
'destination_city.name':destination_city_name
|
| 53 |
}
|
| 54 |
input_df = pd.DataFrame([input_data])
|
|
|
|
| 66 |
predicted_status = "Unknown" if pred[0] == -1 else encoders['status.name'].inverse_transform([pred])[0]
|
| 67 |
probability = pred_proba[0][pred[0]] * 100 if pred[0] != -1 else "Unknown"
|
| 68 |
|
| 69 |
+
if predicted_status == "Returned to Client":
|
| 70 |
probability = 100 - probability
|
| 71 |
|
| 72 |
return {"Probability": round(probability,2)}
|