Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,15 +34,10 @@ all_reps = sorted(df['Rep Name'].dropna().unique())
|
|
34 |
# === Tab 1: Summary ===
|
35 |
def generate_summary(date_str):
|
36 |
day_df = df[df['Date'] == date_str]
|
37 |
-
|
38 |
-
# Active reps and their total stops
|
39 |
active = day_df.groupby('Rep Name').size().reset_index(name='Total Visits')
|
40 |
-
|
41 |
-
# Detect inactive reps
|
42 |
active_list = active['Rep Name'].tolist()
|
43 |
inactive_list = [rep for rep in all_reps if rep not in active_list]
|
44 |
inactive_df = pd.DataFrame({'Inactive Reps': inactive_list})
|
45 |
-
|
46 |
return active, inactive_df
|
47 |
|
48 |
# === Tab 2: KAMs ===
|
@@ -92,7 +87,7 @@ def show_map(date_str, rep):
|
|
92 |
|
93 |
fig.update_layout(mapbox_style="open-street-map", title=f"π {rep}'s Route on {date_str}")
|
94 |
|
95 |
-
# Final table
|
96 |
table = subset[[
|
97 |
'Visit Order', 'Dealership Name', 'Time', 'Time Diff (min)',
|
98 |
'Type of call', 'Sales or service'
|
@@ -104,7 +99,7 @@ def show_map(date_str, rep):
|
|
104 |
'Sales or service': 'πΌ Category'
|
105 |
})
|
106 |
|
107 |
-
#
|
108 |
total_time = round(table['β±οΈ Time Spent'].sum(), 2)
|
109 |
summary_row = pd.DataFrame([{
|
110 |
'Visit Order': '',
|
@@ -126,18 +121,13 @@ with gr.Blocks() as app:
|
|
126 |
date_summary = gr.Dropdown(label="Select Date", choices=sorted(df['Date'].unique(), reverse=True))
|
127 |
active_table = gr.Dataframe(label="β
Active Reps (with total visits)")
|
128 |
inactive_table = gr.Dataframe(label="β οΈ Inactive Reps")
|
129 |
-
|
130 |
date_summary.change(fn=generate_summary, inputs=date_summary, outputs=[active_table, inactive_table])
|
131 |
|
132 |
with gr.Tab("π€ KAM's"):
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
date_picker.change(fn=get_reps, inputs=date_picker, outputs=rep_picker)
|
141 |
-
btn.click(fn=show_map, inputs=[date_picker, rep_picker], outputs=[table, map_plot])
|
142 |
-
|
143 |
-
app.launch()
|
|
|
34 |
# === Tab 1: Summary ===
|
35 |
def generate_summary(date_str):
|
36 |
day_df = df[df['Date'] == date_str]
|
|
|
|
|
37 |
active = day_df.groupby('Rep Name').size().reset_index(name='Total Visits')
|
|
|
|
|
38 |
active_list = active['Rep Name'].tolist()
|
39 |
inactive_list = [rep for rep in all_reps if rep not in active_list]
|
40 |
inactive_df = pd.DataFrame({'Inactive Reps': inactive_list})
|
|
|
41 |
return active, inactive_df
|
42 |
|
43 |
# === Tab 2: KAMs ===
|
|
|
87 |
|
88 |
fig.update_layout(mapbox_style="open-street-map", title=f"π {rep}'s Route on {date_str}")
|
89 |
|
90 |
+
# Final table
|
91 |
table = subset[[
|
92 |
'Visit Order', 'Dealership Name', 'Time', 'Time Diff (min)',
|
93 |
'Type of call', 'Sales or service'
|
|
|
99 |
'Sales or service': 'πΌ Category'
|
100 |
})
|
101 |
|
102 |
+
# Add summary row
|
103 |
total_time = round(table['β±οΈ Time Spent'].sum(), 2)
|
104 |
summary_row = pd.DataFrame([{
|
105 |
'Visit Order': '',
|
|
|
121 |
date_summary = gr.Dropdown(label="Select Date", choices=sorted(df['Date'].unique(), reverse=True))
|
122 |
active_table = gr.Dataframe(label="β
Active Reps (with total visits)")
|
123 |
inactive_table = gr.Dataframe(label="β οΈ Inactive Reps")
|
|
|
124 |
date_summary.change(fn=generate_summary, inputs=date_summary, outputs=[active_table, inactive_table])
|
125 |
|
126 |
with gr.Tab("π€ KAM's"):
|
127 |
+
with gr.Row():
|
128 |
+
with gr.Column(scale=1):
|
129 |
+
date_picker = gr.Dropdown(label="Select Date", choices=sorted(df['Date'].unique(), reverse=True))
|
130 |
+
rep_picker = gr.Dropdown(label="Select Rep")
|
131 |
+
btn = gr.Button("Show Route")
|
132 |
+
with gr.Column(scale=2):
|
133 |
+
table = gr.Dataframe(label="
|
|
|
|
|
|
|
|