Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ df['Visit Order'] = df.groupby(['Rep Name', 'Date']).cumcount() + 1
|
|
| 38 |
# === All reps ===
|
| 39 |
all_reps = sorted(df['Rep Name'].dropna().unique())
|
| 40 |
|
| 41 |
-
# ===
|
| 42 |
def generate_summary(date_str):
|
| 43 |
day_df = df[df['Date'] == date_str]
|
| 44 |
active = day_df.groupby('Rep Name').size().reset_index(name='Total Visits')
|
|
@@ -47,7 +47,6 @@ def generate_summary(date_str):
|
|
| 47 |
inactive_df = pd.DataFrame({'Inactive Reps': inactive_list})
|
| 48 |
return active, inactive_df
|
| 49 |
|
| 50 |
-
# === KAM logic ===
|
| 51 |
def get_reps(date_str):
|
| 52 |
reps = df[df['Date'] == date_str]['Rep Name'].dropna().unique()
|
| 53 |
return gr.update(choices=sorted(reps))
|
|
@@ -118,9 +117,15 @@ def show_map(date_str, rep):
|
|
| 118 |
|
| 119 |
return table, fig
|
| 120 |
|
| 121 |
-
# ===
|
| 122 |
-
def
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
gr.Markdown("## ποΈ Carfind Rep Tracker")
|
| 125 |
|
| 126 |
with gr.Tab("π Summary"):
|
|
@@ -139,26 +144,27 @@ def build_dashboard():
|
|
| 139 |
table = gr.Dataframe(label="Call Table")
|
| 140 |
|
| 141 |
map_plot = gr.Plot(label="Map")
|
|
|
|
| 142 |
date_picker.change(fn=get_reps, inputs=date_picker, outputs=rep_picker)
|
| 143 |
btn.click(fn=show_map, inputs=[date_picker, rep_picker], outputs=[table, map_plot])
|
| 144 |
-
return
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
| 38 |
# === All reps ===
|
| 39 |
all_reps = sorted(df['Rep Name'].dropna().unique())
|
| 40 |
|
| 41 |
+
# === Dashboard Logic ===
|
| 42 |
def generate_summary(date_str):
|
| 43 |
day_df = df[df['Date'] == date_str]
|
| 44 |
active = day_df.groupby('Rep Name').size().reset_index(name='Total Visits')
|
|
|
|
| 47 |
inactive_df = pd.DataFrame({'Inactive Reps': inactive_list})
|
| 48 |
return active, inactive_df
|
| 49 |
|
|
|
|
| 50 |
def get_reps(date_str):
|
| 51 |
reps = df[df['Date'] == date_str]['Rep Name'].dropna().unique()
|
| 52 |
return gr.update(choices=sorted(reps))
|
|
|
|
| 117 |
|
| 118 |
return table, fig
|
| 119 |
|
| 120 |
+
# === Login Auth ===
|
| 121 |
+
def check_login(email, password):
|
| 122 |
+
if email in allowed_users and allowed_users[email] == password:
|
| 123 |
+
return True
|
| 124 |
+
return False
|
| 125 |
+
|
| 126 |
+
# === MAIN APP ===
|
| 127 |
+
def main_app():
|
| 128 |
+
with gr.Blocks() as app:
|
| 129 |
gr.Markdown("## ποΈ Carfind Rep Tracker")
|
| 130 |
|
| 131 |
with gr.Tab("π Summary"):
|
|
|
|
| 144 |
table = gr.Dataframe(label="Call Table")
|
| 145 |
|
| 146 |
map_plot = gr.Plot(label="Map")
|
| 147 |
+
|
| 148 |
date_picker.change(fn=get_reps, inputs=date_picker, outputs=rep_picker)
|
| 149 |
btn.click(fn=show_map, inputs=[date_picker, rep_picker], outputs=[table, map_plot])
|
| 150 |
+
return app
|
| 151 |
+
|
| 152 |
+
# === LOGIN WRAPPER ===
|
| 153 |
+
with gr.Blocks() as login_app:
|
| 154 |
+
gr.Markdown("## π Login to Access Carfind Dashboard")
|
| 155 |
+
email = gr.Textbox(label="Email")
|
| 156 |
+
password = gr.Textbox(label="Password", type="password")
|
| 157 |
+
login_btn = gr.Button("Login")
|
| 158 |
+
login_status = gr.Markdown("")
|
| 159 |
+
|
| 160 |
+
def do_login(user_email, user_password):
|
| 161 |
+
if check_login(user_email, user_password):
|
| 162 |
+
import gradio as gr2
|
| 163 |
+
login_app.close()
|
| 164 |
+
main_app().launch(share=False) # launch the main app
|
| 165 |
+
else:
|
| 166 |
+
return "β Invalid credentials. Try again."
|
| 167 |
+
|
| 168 |
+
login_btn.click(fn=do_login, inputs=[email, password], outputs=[login_status])
|
| 169 |
+
|
| 170 |
+
login_app.launch()
|