DrGabrielLopez commited on
Commit
9ca2045
·
verified ·
1 Parent(s): 8723265

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -0
app.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+
5
+
6
+ def run_model(file):
7
+ if file is None:
8
+ return "Please upload a file", "Please upload a file", "Please upload a file"
9
+
10
+ # Placeholder prediction logic
11
+ max_credit_limit = 87500
12
+ mean_credit_limit = 42300
13
+ min_credit_limit = 15000
14
+
15
+ return (
16
+ f"${max_credit_limit:,.0f}",
17
+ f"${mean_credit_limit:,.0f}",
18
+ f"${min_credit_limit:,.0f}",
19
+ )
20
+
21
+
22
+ def load_fake_data():
23
+ rng = np.random.default_rng(42)
24
+ n = 30
25
+
26
+ customer_names = [f"Customer {i+1}" for i in range(n)]
27
+ tax_ids = [f"{rng.integers(10, 99)}.{rng.integers(100, 999)}.{rng.integers(100, 999)}/0001-{rng.integers(10, 99)}" for _ in range(n)]
28
+ mcust_no = [f"MC{rng.integers(100000, 999999)}" for _ in range(n)]
29
+
30
+ credit_limit = rng.integers(5000, 95000, n)
31
+ max_credit_limit = credit_limit + rng.integers(1000, 15000, n)
32
+ min_credit_limit = credit_limit - rng.integers(1000, 10000, n)
33
+ min_credit_limit = np.clip(min_credit_limit, 0, None)
34
+
35
+ return pd.DataFrame({
36
+ "customer_name": customer_names,
37
+ "tax_id": tax_ids,
38
+ "mcust_no": mcust_no,
39
+ "credit_limit": credit_limit,
40
+ "max_credit_limit": max_credit_limit,
41
+ "min_credit_limit": min_credit_limit,
42
+ })
43
+
44
+
45
+ with gr.Blocks(title="Credit Limit Model") as demo:
46
+ # ---------- Header ----------
47
+ gr.Markdown("# Credit Limit Model")
48
+ gr.Markdown("AI-based credit limit model to automatically predict credit-lines.")
49
+ gr.Markdown("⚠️ **The current model is limited to new small clients (with expected credit lines below 100K).**")
50
+
51
+ gr.Markdown("---")
52
+
53
+ # ---------- Section 1: New prediction ----------
54
+ gr.Markdown("## Make a new prediction")
55
+ gr.Markdown("Upload your excel template to have a company analysed")
56
+
57
+ with gr.Row():
58
+ with gr.Column():
59
+ gr.Markdown("### Prediction Results")
60
+ max_out = gr.Textbox(label="Max Credit Limit", value="$XXX", interactive=False)
61
+ mean_out = gr.Textbox(label="Mean Credit Limit", value="$XXX", interactive=False)
62
+ min_out = gr.Textbox(label="Min Credit Limit", value="$XXX", interactive=False)
63
+
64
+ with gr.Column():
65
+ file_input = gr.File(label="Upload Excel template", file_types=[".xlsx", ".xls", ".xlsm"])
66
+ run_button = gr.Button("Run Model")
67
+
68
+ run_button.click(fn=run_model, inputs=file_input, outputs=[max_out, mean_out, min_out])
69
+
70
+ gr.Markdown("---")
71
+
72
+ # ---------- Section 2: Past predictions ----------
73
+ gr.Markdown("## Visualize past predictions")
74
+ gr.Dataframe(value=load_fake_data(), interactive=False, wrap=True)
75
+
76
+
77
+ if __name__ == "__main__":
78
+ demo.launch()