IAMTFRMZA commited on
Commit
cfd2f6b
·
verified ·
1 Parent(s): 5fab790

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py CHANGED
@@ -18,6 +18,29 @@ client = gspread.authorize(creds)
18
 
19
  SHEET_URL = "https://docs.google.com/spreadsheets/d/1if4KoVQvw5ZbhknfdZbzMkcTiPfsD6bz9V3a1th-bwQ"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  # -------------------- UTILS --------------------
22
  def normalize_columns(cols):
23
  return [c.strip().title() for c in cols]
@@ -320,6 +343,44 @@ with gr.Blocks(title="Graffiti Admin Dashboard") as app:
320
  save_btn = gr.Button("Save Users")
321
  save_out = gr.Textbox()
322
  save_btn.click(save_users, users_tbl, save_out)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
 
324
  app.launch()
325
 
 
18
 
19
  SHEET_URL = "https://docs.google.com/spreadsheets/d/1if4KoVQvw5ZbhknfdZbzMkcTiPfsD6bz9V3a1th-bwQ"
20
 
21
+ # -------------------- Self Sourced Leads --------------------
22
+ SHEET_MAP = {
23
+ "Alice": "https://docs.google.com/spreadsheets/d/18qFpkbE2CwVOgiB6Xz4m2Ep7ZA29p5xV",
24
+ "Bob": "https://docs.google.com/spreadsheets/d/1EKngyAvq_3hzQMAOVame2nO9LKPJEV0d",
25
+ "Charlie": "https://docs.google.com/spreadsheets/d/164OTu1keBC12-5XFUDXMmLOPMkdAjBOM",
26
+ "Dave": "https://docs.google.com/spreadsheets/d/1m5e6YXxjK62vtBxYGkJSyHpHT7lnirg6"
27
+ }
28
+
29
+ def load_leads_data(rep_name):
30
+ if rep_name not in SHEET_MAP:
31
+ return pd.DataFrame([{"Error": f"No sheet available for '{rep_name}'"}])
32
+
33
+ sheet_url = SHEET_MAP[rep_name]
34
+ try:
35
+ sheet = client.open_by_url(sheet_url)
36
+ worksheet = sheet.get_worksheet(0)
37
+ data = worksheet.get_all_values()
38
+ if not data:
39
+ return pd.DataFrame([{"Info": "No data available"}])
40
+ return pd.DataFrame(data[1:], columns=data[0])
41
+ except Exception as e:
42
+ return pd.DataFrame([{"Error": str(e)}])
43
+
44
  # -------------------- UTILS --------------------
45
  def normalize_columns(cols):
46
  return [c.strip().title() for c in cols]
 
343
  save_btn = gr.Button("Save Users")
344
  save_out = gr.Textbox()
345
  save_btn.click(save_users, users_tbl, save_out)
346
+ # -------------------- Self Sourced Leads --------------------
347
+ SHEET_MAP = {
348
+ "Alice": "https://docs.google.com/spreadsheets/d/18qFpkbE2CwVOgiB6Xz4m2Ep7ZA29p5xV",
349
+ "Bob": "https://docs.google.com/spreadsheets/d/1EKngyAvq_3hzQMAOVame2nO9LKPJEV0d",
350
+ "Charlie": "https://docs.google.com/spreadsheets/d/164OTu1keBC12-5XFUDXMmLOPMkdAjBOM",
351
+ "Dave": "https://docs.google.com/spreadsheets/d/1m5e6YXxjK62vtBxYGkJSyHpHT7lnirg6"
352
+ }
353
+
354
+ def load_leads_data(rep_name):
355
+ if rep_name not in SHEET_MAP:
356
+ return pd.DataFrame([{"Error": f"No sheet available for '{rep_name}'"}])
357
+
358
+ sheet_url = SHEET_MAP[rep_name]
359
+ try:
360
+ sheet = client.open_by_url(sheet_url)
361
+ worksheet = sheet.get_worksheet(0)
362
+ data = worksheet.get_all_values()
363
+ if not data:
364
+ return pd.DataFrame([{"Info": "No data available"}])
365
+ return pd.DataFrame(data[1:], columns=data[0])
366
+ except Exception as e:
367
+ return pd.DataFrame([{"Error": str(e)}])
368
+ # -- Self Sourced Leads Tab (New) --
369
+ with gr.Tab("Self Sourced Leads"):
370
+ gr.Markdown("## 🔍 Self Sourced Leads by Rep")
371
+
372
+ rep_leads = gr.Dropdown(
373
+ label="Select Rep",
374
+ choices=list(SHEET_MAP.keys()),
375
+ allow_custom_value=True
376
+ )
377
+ btn_load_leads = gr.Button("Load Leads")
378
+ tbl_leads = gr.Dataframe(label="Leads Data")
379
+
380
+ btn_load_leads.click(load_leads_data, rep_leads, tbl_leads)
381
+
382
+ app.launch()
383
+
384
 
385
  app.launch()
386