Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,10 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
| 4 |
|
| 5 |
-
# Load model and feature names once (for performance)
|
| 6 |
model = joblib.load("ar_overdue_model.joblib")
|
| 7 |
feature_names = joblib.load("ar_model_features.joblib")
|
| 8 |
|
| 9 |
def predict(company_code, document_type, amount, due_in_days):
|
| 10 |
-
# Prepare input as DataFrame
|
| 11 |
input_dict = {
|
| 12 |
"company_code": company_code,
|
| 13 |
"document_type": document_type,
|
|
@@ -16,12 +14,10 @@ def predict(company_code, document_type, amount, due_in_days):
|
|
| 16 |
}
|
| 17 |
input_df = pd.DataFrame([input_dict])
|
| 18 |
input_df = pd.get_dummies(input_df)
|
| 19 |
-
# Ensure all model columns are present
|
| 20 |
for col in feature_names:
|
| 21 |
if col not in input_df.columns:
|
| 22 |
input_df[col] = 0
|
| 23 |
input_df = input_df[feature_names]
|
| 24 |
-
# Predict
|
| 25 |
proba = model.predict_proba(input_df)[0,1]
|
| 26 |
pred = model.predict(input_df)[0]
|
| 27 |
return f"Overdue: {bool(pred)} (Probability: {proba:.2f})"
|
|
@@ -34,9 +30,8 @@ iface = gr.Interface(
|
|
| 34 |
gr.Number(label="Amount"),
|
| 35 |
gr.Number(label="Due In Days")
|
| 36 |
],
|
| 37 |
-
outputs="text"
|
| 38 |
-
title="SAP AR Overdue Predictor"
|
| 39 |
)
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
-
iface.launch()
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
| 4 |
|
|
|
|
| 5 |
model = joblib.load("ar_overdue_model.joblib")
|
| 6 |
feature_names = joblib.load("ar_model_features.joblib")
|
| 7 |
|
| 8 |
def predict(company_code, document_type, amount, due_in_days):
|
|
|
|
| 9 |
input_dict = {
|
| 10 |
"company_code": company_code,
|
| 11 |
"document_type": document_type,
|
|
|
|
| 14 |
}
|
| 15 |
input_df = pd.DataFrame([input_dict])
|
| 16 |
input_df = pd.get_dummies(input_df)
|
|
|
|
| 17 |
for col in feature_names:
|
| 18 |
if col not in input_df.columns:
|
| 19 |
input_df[col] = 0
|
| 20 |
input_df = input_df[feature_names]
|
|
|
|
| 21 |
proba = model.predict_proba(input_df)[0,1]
|
| 22 |
pred = model.predict(input_df)[0]
|
| 23 |
return f"Overdue: {bool(pred)} (Probability: {proba:.2f})"
|
|
|
|
| 30 |
gr.Number(label="Amount"),
|
| 31 |
gr.Number(label="Due In Days")
|
| 32 |
],
|
| 33 |
+
outputs="text"
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
| 37 |
+
iface.launch(ssr_mode=False)
|