VyLala commited on
Commit
667073b
Β·
verified Β·
1 Parent(s): 2d64447

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -56,7 +56,12 @@ with gr.Blocks() as interface:
56
  # output_flag = gr.Markdown(elem_id="output-flag")
57
 
58
  # gr.Markdown("---")
59
-
 
 
 
 
 
60
  with gr.Accordion("Open to See the Output Table", open=False) as table_accordion:
61
  output_table = gr.HTML(render=True)
62
  #with gr.Row():
@@ -290,8 +295,10 @@ with gr.Blocks() as interface:
290
  # "βœ… Done",
291
  # "\n".join(log_lines)
292
  # )
293
-
294
- def log_submission_to_gsheet(email, samples):
 
 
295
  from datetime import datetime, timezone
296
  import json, os, gspread
297
  from oauth2client.service_account import ServiceAccountCredentials
@@ -315,7 +322,7 @@ with gr.Blocks() as interface:
315
  email_col = headers.index("email")
316
  samples_col = headers.index("samples")
317
  recent_time_col = headers.index("recent_time")
318
-
319
  # Step 1: Find row matching the email
320
  for i, row in enumerate(data[1:], start=2): # start=2 for correct row indexing
321
  if row[email_col].strip().lower() == email.strip().lower():
@@ -333,7 +340,8 @@ with gr.Blocks() as interface:
333
 
334
  worksheet.update_cell(i, samples_col + 1, new_sample_string)
335
  worksheet.update_cell(i, recent_time_col + 1, new_timestamp)
336
-
 
337
  print(f"βœ… Updated existing user row for: {email}")
338
  return
339
 
@@ -342,6 +350,10 @@ with gr.Blocks() as interface:
342
  new_row[email_col] = email
343
  new_row[samples_col] = ", ".join(samples)
344
  new_row[recent_time_col] = timestamp
 
 
 
 
345
  worksheet.append_row(new_row)
346
  print(f"βœ… Appended new user row for: {email}")
347
 
@@ -742,7 +754,7 @@ with gr.Blocks() as interface:
742
  )
743
 
744
 
745
-
746
 
747
  stop_button.click(fn=stop_batch, inputs=[], outputs=[status])
748
 
@@ -789,6 +801,10 @@ with gr.Blocks() as interface:
789
  inputs=[raw_text, q1, q2, contact],
790
  outputs=[feedback_status]
791
  )
 
 
 
 
792
  gr.HTML("""
793
  <style>
794
  body, html {
 
56
  # output_flag = gr.Markdown(elem_id="output-flag")
57
 
58
  # gr.Markdown("---")
59
+
60
+ nps_question = gr.Markdown("#### πŸ“ How likely are you to recommend this tool to a colleague or peer (0 = Not at all, 10 = Definitely)?")
61
+ nps_slider = gr.Slider(minimum=0, maximum=10, step=1, label="Your NPS Score (0-10)")
62
+ nps_button = gr.Button("Submit NPS")
63
+ nps_output = gr.Textbox(label="Thanks for your feedback!")
64
+
65
  with gr.Accordion("Open to See the Output Table", open=False) as table_accordion:
66
  output_table = gr.HTML(render=True)
67
  #with gr.Row():
 
295
  # "βœ… Done",
296
  # "\n".join(log_lines)
297
  # )
298
+ def submit_nps(email,nps_score):
299
+ log_submission_to_gsheet(email,"",nps_score)
300
+
301
+ def log_submission_to_gsheet(email, samples, nps_score=None):
302
  from datetime import datetime, timezone
303
  import json, os, gspread
304
  from oauth2client.service_account import ServiceAccountCredentials
 
322
  email_col = headers.index("email")
323
  samples_col = headers.index("samples")
324
  recent_time_col = headers.index("recent_time")
325
+ nps_col = headers.index("nps_score") if "nps_score" in headers else -1
326
  # Step 1: Find row matching the email
327
  for i, row in enumerate(data[1:], start=2): # start=2 for correct row indexing
328
  if row[email_col].strip().lower() == email.strip().lower():
 
340
 
341
  worksheet.update_cell(i, samples_col + 1, new_sample_string)
342
  worksheet.update_cell(i, recent_time_col + 1, new_timestamp)
343
+ if nps_score is not None:
344
+ worksheet.update_cell(i, nps_col + 1, str(nps_score))
345
  print(f"βœ… Updated existing user row for: {email}")
346
  return
347
 
 
350
  new_row[email_col] = email
351
  new_row[samples_col] = ", ".join(samples)
352
  new_row[recent_time_col] = timestamp
353
+ if nps_col != -1:
354
+ if len(new_row) <= nps_col:
355
+ new_row.extend([""] * (nps_col + 1 - len(new_row)))
356
+ new_row[nps_col] = str(nps_score) if nps_score is not None else ""
357
  worksheet.append_row(new_row)
358
  print(f"βœ… Appended new user row for: {email}")
359
 
 
754
  )
755
 
756
 
757
+
758
 
759
  stop_button.click(fn=stop_batch, inputs=[], outputs=[status])
760
 
 
801
  inputs=[raw_text, q1, q2, contact],
802
  outputs=[feedback_status]
803
  )
804
+
805
+ nps_button.click(fn=submit_nps, inputs=[user_email, nps_slider], outputs=nps_output)
806
+
807
+
808
  gr.HTML("""
809
  <style>
810
  body, html {