IAMTFRMZA commited on
Commit
6cca50e
Β·
verified Β·
1 Parent(s): bc2d37c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -26
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
- # === Summary 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,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
- # === Gradio App ===
122
- def build_dashboard():
123
- with gr.Blocks() as dashboard:
 
 
 
 
 
 
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 dashboard
145
-
146
- def authenticate(email, password):
147
- if email in allowed_users and allowed_users[email] == password:
148
- return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
149
- else:
150
- return "Invalid login", None, None
151
-
152
- with gr.Blocks() as app:
153
- gr.Markdown("## πŸ” Login to Access Carfind Rep Tracker")
154
- with gr.Row():
155
- email_input = gr.Textbox(label="Email")
156
- pass_input = gr.Textbox(label="Password", type="password")
157
- login_button = gr.Button("Login")
158
- error_box = gr.Markdown("", visible=False)
159
- dashboard = build_dashboard()
160
- dashboard.visible = False
161
-
162
- login_button.click(fn=authenticate, inputs=[email_input, pass_input], outputs=[error_box, error_box, dashboard])
163
-
164
- app.launch()
 
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()