GenAICoder commited on
Commit
05e0b12
·
verified ·
1 Parent(s): a32ecf8

Update appv1.py

Browse files
Files changed (1) hide show
  1. appv1.py +74 -27
appv1.py CHANGED
@@ -1,7 +1,7 @@
1
- # app.py
2
-
3
  import pandas as pd
 
4
 
 
5
 
6
  from helper.vintage_helpers import(
7
  create_booking_vintage
@@ -11,22 +11,17 @@ from helper.data_merger import(
11
  merge_acq_perf
12
  )
13
 
14
-
15
- from analytics.monitoring_analysis import (
16
- generate_monitoring_table
17
- )
18
-
19
  from metrics.mix_metrics import (
20
  calculate_count_mix,
21
  calculate_limit_mix
22
  )
23
 
24
-
 
 
25
  acq = pd.read_csv("data/acquisition.csv")
26
-
27
  perf = pd.read_csv("data/performance.csv")
28
 
29
-
30
  acq= create_booking_vintage(
31
  acq,
32
  booking_date_col="booking_date"
@@ -38,27 +33,79 @@ perf = merge_acq_perf(
38
  )
39
 
40
 
41
- # Example 1
42
- channel_mix = calculate_count_mix(
43
- acq,
44
- group_col="sourcing_channel"
45
- )
46
 
47
- print(channel_mix)
48
 
 
49
 
50
- # Example 2
51
- limit_mix = calculate_limit_mix(
52
- acq,
53
- group_col="fico_band"
54
- )
55
 
56
- print(limit_mix)
 
57
 
 
 
58
 
59
- # Example 3
60
- monitoring_table = generate_monitoring_table(
61
- perf
62
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
- print(monitoring_table)
 
 
 
1
  import pandas as pd
2
+ import gradio as gr
3
 
4
+ from analytics.monitoring_analysis import generate_monitoring_table
5
 
6
  from helper.vintage_helpers import(
7
  create_booking_vintage
 
11
  merge_acq_perf
12
  )
13
 
 
 
 
 
 
14
  from metrics.mix_metrics import (
15
  calculate_count_mix,
16
  calculate_limit_mix
17
  )
18
 
19
+ # ------------------------
20
+ # Load Data
21
+ # ------------------------
22
  acq = pd.read_csv("data/acquisition.csv")
 
23
  perf = pd.read_csv("data/performance.csv")
24
 
 
25
  acq= create_booking_vintage(
26
  acq,
27
  booking_date_col="booking_date"
 
33
  )
34
 
35
 
36
+ # ------------------------
37
+ # Core Engine
38
+ # ------------------------
39
+ def run_analysis(dataset, analysis_type, group_col):
 
40
 
41
+ if dataset == "Acquisition":
42
 
43
+ df = acq
44
 
45
+ if analysis_type == "Count Mix":
46
+ return calculate_count_mix(df, group_col)
 
 
 
47
 
48
+ elif analysis_type == "Limit Mix":
49
+ return calculate_limit_mix(df, group_col)
50
 
51
+ else:
52
+ return "Invalid analysis type for Acquisition dataset"
53
 
54
+ elif dataset == "Performance":
55
+
56
+ df = perf
57
+
58
+ if analysis_type == "Vintage Monitoring Table":
59
+ return generate_monitoring_table(df)
60
+
61
+ else:
62
+ return "Invalid analysis type for Performance dataset"
63
+
64
+ else:
65
+ return "Invalid dataset selection"
66
+
67
+
68
+ # ------------------------
69
+ # Gradio UI
70
+ # ------------------------
71
+ with gr.Blocks() as app:
72
+
73
+ gr.Markdown("# 📊 Risk Analytics Manager Agent (V1)")
74
+
75
+ with gr.Row():
76
+
77
+ dataset = gr.Dropdown(
78
+ choices=["Acquisition", "Performance"],
79
+ label="Select Dataset"
80
+ )
81
+
82
+ analysis_type = gr.Dropdown(
83
+ choices=[
84
+ "Count Mix",
85
+ "Limit Mix",
86
+ "Vintage Monitoring Table"
87
+ ],
88
+ label="Select Analysis"
89
+ )
90
+
91
+ group_col = gr.Dropdown(
92
+ choices=[
93
+ "sourcing_channel",
94
+ "fico_band",
95
+ "city_tier",
96
+ "occupation_type"
97
+ ],
98
+ label="Group Column (for Mix)"
99
+ )
100
+
101
+ run_btn = gr.Button("Run Analysis")
102
+
103
+ output = gr.Dataframe()
104
+
105
+ run_btn.click(
106
+ fn=run_analysis,
107
+ inputs=[dataset, analysis_type, group_col],
108
+ outputs=output
109
+ )
110
 
111
+ app.launch()