Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 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,
|
| 12 |
+
"amount": amount,
|
| 13 |
+
"due_in_days": due_in_days
|
| 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})"
|
| 24 |
+
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=predict,
|
| 27 |
+
inputs=[
|
| 28 |
+
gr.Dropdown(['CompanyA', 'CompanyB', 'CompanyC'], label="Company Code"),
|
| 29 |
+
gr.Dropdown(['INV', 'CRN', 'DBN'], label="Document Type"),
|
| 30 |
+
gr.Number(label="Amount"),
|
| 31 |
+
gr.Number(label="Due In Days")
|
| 32 |
+
],
|
| 33 |
+
outputs="text",
|
| 34 |
+
title="SAP AR Overdue Predictor"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
iface.launch()
|