nghweigeok commited on
Commit
63aadc4
·
verified ·
1 Parent(s): f41ec06

15th deployment. Overhaul user interface. Add bucket fullness chart. Hide file upload widget.

Browse files
app.py CHANGED
@@ -151,6 +151,96 @@ def plot_model_results(results_df, average_value, title, model_type):
151
  return img
152
 
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  def call_r_script(
155
  input_file,
156
  text_output_path,
@@ -252,9 +342,6 @@ def analyze_excel_single(file_path):
252
  # Check if Driver and Builder sheets are present in the dataset
253
  trustbuilder_present = "Builder" in excel_file.sheet_names
254
 
255
- # elif ".csv" in file_path:
256
- # df = pd.read_csv(file_path)
257
-
258
  # Step 1: Check for missing columns and handle NPS column
259
  required_columns = [
260
  "Trust",
@@ -334,6 +421,14 @@ def analyze_excel_single(file_path):
334
  with open(text_output_path, "r") as file:
335
  output_text = file.read()
336
 
 
 
 
 
 
 
 
 
337
  # Get n_samples from output text
338
  n_samples_trust = output_text.split(": Trust")[1]
339
  n_samples_trust = n_samples_trust.split("Analysis based on ")[1]
@@ -346,10 +441,12 @@ def analyze_excel_single(file_path):
346
  img_trust = plot_model_results(
347
  results_df_trust,
348
  average_value_trust,
349
- f"TrustLogic® Drivers\n(What drives your trust)\nn={n_samples_trust}",
 
350
  "Trust",
351
  )
352
 
 
353
  img_nps = None
354
  if nps_present:
355
  # Get n_samples from output text
@@ -363,10 +460,12 @@ def analyze_excel_single(file_path):
363
  img_nps = plot_model_results(
364
  results_df_nps,
365
  average_value_nps,
366
- f"TrustLogic® Drivers\n(What drives your NPS)\nn={n_samples_nps}",
 
367
  "NPS",
368
  )
369
 
 
370
  img_loyalty = None
371
  if loyalty_present:
372
  # Get n_samples from output text
@@ -382,10 +481,12 @@ def analyze_excel_single(file_path):
382
  img_loyalty = plot_model_results(
383
  results_df_loyalty,
384
  average_value_loyalty,
385
- f"TrustLogic® Drivers\n(What drives your Loyalty)\nn={n_samples_loyalty}",
 
386
  "Loyalty",
387
  )
388
 
 
389
  img_consideration = None
390
  if consideration_present:
391
  # Get n_samples from output text
@@ -403,10 +504,12 @@ def analyze_excel_single(file_path):
403
  img_consideration = plot_model_results(
404
  results_df_consideration,
405
  average_value_consideration,
406
- f"TrustLogic® Drivers\n(What drives your Consideration)\nn={n_samples_consideration}",
 
407
  "Consideration",
408
  )
409
 
 
410
  img_satisfaction = None
411
  if satisfaction_present:
412
  # Get n_samples from output text
@@ -424,10 +527,12 @@ def analyze_excel_single(file_path):
424
  img_satisfaction = plot_model_results(
425
  results_df_satisfaction,
426
  average_value_satisfaction,
427
- f"TrustLogic® Drivers\n(What drives your Satisfaction)\nn={n_samples_satisfaction}",
 
428
  "Satisfaction",
429
  )
430
 
 
431
  df_builder = None
432
  df_builder_pivot = None
433
  if trustbuilder_present:
@@ -541,6 +646,7 @@ def analyze_excel_single(file_path):
541
  )
542
 
543
  return (
 
544
  img_trust,
545
  img_nps,
546
  img_loyalty,
@@ -569,6 +675,7 @@ def batch_file_processing(file_paths):
569
  """
570
 
571
  # Process each file
 
572
  img_trust_list = []
573
  img_nps_list = []
574
  img_loyalty_list = []
@@ -580,6 +687,7 @@ def batch_file_processing(file_paths):
580
 
581
  for file_path in file_paths:
582
  (
 
583
  img_trust,
584
  img_nps,
585
  img_loyalty,
@@ -589,6 +697,7 @@ def batch_file_processing(file_paths):
589
  df_builder_pivot,
590
  output_text,
591
  ) = analyze_excel_single(file_path)
 
592
  img_trust_list.append(img_trust)
593
  img_nps_list.append(img_nps)
594
  img_loyalty_list.append(img_loyalty)
@@ -599,6 +708,7 @@ def batch_file_processing(file_paths):
599
  output_text_list.append(output_text)
600
 
601
  return (
 
602
  img_trust_list,
603
  img_nps_list,
604
  img_loyalty_list,
@@ -631,6 +741,7 @@ def variable_outputs(file_inputs):
631
 
632
  # Call batch file processing and get analysis results
633
  (
 
634
  img_trust_list,
635
  img_nps_list,
636
  img_loyalty_list,
@@ -649,6 +760,7 @@ def variable_outputs(file_inputs):
649
 
650
  # Use zip_longest to iterate over the lists, padding with None
651
  for row, (
 
652
  img_trust,
653
  img_nps,
654
  img_loyalty,
@@ -659,6 +771,7 @@ def variable_outputs(file_inputs):
659
  output_text,
660
  ) in enumerate(
661
  zip_longest(
 
662
  img_trust_list,
663
  img_nps_list,
664
  img_loyalty_list,
@@ -674,6 +787,29 @@ def variable_outputs(file_inputs):
674
 
675
  # Based on the number of files uploaded, determine the content of each textbox
676
  plots = [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677
  gr.Image(
678
  value=img_trust,
679
  type="pil",
@@ -688,30 +824,50 @@ def variable_outputs(file_inputs):
688
  label="NPS Drivers",
689
  visible=True,
690
  ),
691
- # gr.Image(
692
- # value=img_loyalty,
693
- # type="pil",
694
- # #label=f"{dataset_name}: Loyalty Drivers",
695
- # visible=True,
696
- # ),
697
- # gr.Image(
698
- # value=img_consideration,
699
- # type="pil",
700
- # #label=f"{dataset_name}: Consideration Drivers",
701
- # visible=True,
702
- # ),
703
- # gr.Image(
704
- # value=img_satisfaction,
705
- # type="pil",
706
- # #label=f"{dataset_name}: Satisfaction Drivers",
707
- # visible=True,
708
- # ),
709
- # gr.Textbox(
710
- # value=output_text,
711
- # #label=f"{dataset_name}: Analysis Summary",
712
- # visible=False,
713
- # ),
714
- gr.Dataframe(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
715
  value=df_builder,
716
  headers=list(df_builder.columns),
717
  interactive=False,
@@ -719,8 +875,8 @@ def variable_outputs(file_inputs):
719
  visible=True,
720
  height=800,
721
  wrap=True,
722
- ),
723
- gr.Dataframe(
724
  value=df_builder_pivot,
725
  headers=list(df_builder_pivot.columns),
726
  interactive=False,
@@ -728,23 +884,38 @@ def variable_outputs(file_inputs):
728
  visible=True,
729
  height=800,
730
  wrap=True,
731
- ),
732
- ]
733
 
734
- # add current plots to container
735
- plots_visible += plots
 
 
 
 
 
 
 
 
 
 
 
736
 
737
  plots_invisible = [
738
- # gr.Image(label="Trust Drivers", visible=False),
739
- # gr.Image(label="NPS Drivers", visible=False),
740
- # gr.Image(label="Loyalty Drivers", visible=False),
741
- # gr.Image(label="Consideration Drivers", visible=False),
742
- # gr.Image(label="Satisfaction Drivers", visible=False),
743
- # gr.Textbox(label="Analysis Summary", visible=False),
744
  gr.Image(label="Trust Drivers", visible=False),
745
  gr.Image(label="NPS Drivers", visible=False),
746
- gr.Dataframe(label=" ", visible=False),
747
- gr.Dataframe(label=" ", visible=False),
 
 
 
 
 
 
748
  ]
749
 
750
  return plots_visible + plots_invisible * (max_outputs - k)
@@ -755,55 +926,83 @@ def reset_outputs():
755
  outputs = []
756
 
757
  # Create fixed dummy components
758
- # trust_plot = gr.Image(value=None, label="Trust Drivers", visible=True)
759
- # nps_plot = gr.Image(value=None, label="NPS Drivers", visible=True)
760
- # loyalty_plot = gr.Image(value=None, label="Loyalty Drivers", visible=True)
761
- # consideration_plot = gr.Image(
762
- # value=None, label="Consideration Drivers", visible=True
763
- # )
764
- # satisfaction_plot = gr.Image(
765
- # value=None, label="Satisfaction Drivers", visible=True
766
- # )
767
- # summary_text = gr.Textbox(value=None, label="Analysis Summary", visible=False)
 
 
 
 
 
 
 
 
768
  trust_plot = gr.Image(value=None, label="Trust Drivers", visible=True)
769
  nps_plot = gr.Image(value=None, label="NPS Drivers", visible=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
770
  df_builder = gr.Dataframe(value=None, label=" ", visible=True)
771
  df_builder_pivot = gr.Dataframe(value=None, label=" ", visible=True)
 
 
 
 
 
 
772
  outputs.append(trust_plot)
773
  outputs.append(nps_plot)
 
 
 
 
 
 
774
  outputs.append(df_builder)
775
  outputs.append(df_builder_pivot)
776
- # outputs.append(loyalty_plot)
777
- # outputs.append(satisfaction_plot)
778
- # outputs.append(consideration_plot)
779
- # outputs.append(summary_text)
780
 
781
  # invisible from second set onwards
782
  for i in range(1, max_outputs):
783
- # trust_plot = gr.Image(value=None, label="Trust Drivers", visible=False)
784
- # nps_plot = gr.Image(value=None, label="NPS Drivers", visible=False)
785
- # loyalty_plot = gr.Image(
786
- # value=None, label="Loyalty Drivers", visible=False
787
- # )
788
- # consideration_plot = gr.Image(
789
- # value=None, label="Consideration Drivers", visible=False
790
- # )
791
- # satisfaction_plot = gr.Image(
792
- # value=None, label="Satisfaction Drivers", visible=False
793
- # )
794
- # summary_text = gr.Textbox(value=None, label="Analysis Summary", visible=False)
795
- trust_plot = gr.Image(value=None, label="Trust Drivers", visible=False)
796
- nps_plot = gr.Image(value=None, label="NPS Drivers", visible=False)
797
- df_builder = gr.Dataframe(value=None, label=" ", visible=False)
798
- df_builder_pivot = gr.Dataframe(value=None, label=" ", visible=False)
799
- outputs.append(trust_plot)
800
- outputs.append(nps_plot)
801
- outputs.append(df_builder)
802
- outputs.append(df_builder_pivot)
803
- # outputs.append(loyalty_plot)
804
- # outputs.append(consideration_plot)
805
- # outputs.append(satisfaction_plot)
806
- # outputs.append(summary_text)
807
 
808
  return outputs
809
 
@@ -812,6 +1011,7 @@ def process_examples(file_name):
812
  file_path = f"example_files/{file_name[0]}"
813
  file_path = [file_path]
814
  outputs = variable_outputs(file_path)
 
815
  return outputs
816
 
817
 
@@ -862,50 +1062,144 @@ def process_examples(file_name):
862
  # dataset.click(fn=process_examples, inputs=dataset, outputs=outputs)
863
 
864
  with gr.Blocks() as demo:
865
- # with gr.Column():
866
- # title = gr.Markdown("# TrustLogic & NPS Driver Analysis (Batch Version)")
867
- # description = gr.Markdown(instruction_text)
 
 
 
 
 
 
 
 
868
 
869
  with gr.Column():
870
  with gr.Row():
871
- dataset = gr.Dataset(
872
- components=[gr.Textbox(visible=False)],
873
- label="Select an example to calculate the Donor Drivers from the underlying Excel files",
874
- type="values",
875
- samples=[
876
- ["VW.xlsx"],
877
- # ["HSBC.xlsx"],
878
- # ["CBA.xlsx"],
879
- # ["Red Cross.xlsx"],
880
- # ["Health Insurance.xlsx"],
881
- # ["WV.xlsx"],
882
- # ["Care.xlsx"],
883
- # ["BUPA.xlsx"],
884
- ],
885
- )
886
 
887
  with gr.Row():
888
- # set file upload widget
889
- file_inputs = gr.Files(label="Excel Dataset")
 
890
 
891
  with gr.Row():
892
- # set clear and submit butttons
893
- clear_button = gr.ClearButton(file_inputs)
894
- submit_button = gr.Button("Submit", variant="primary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
895
 
896
  with gr.Column():
897
  # set default output widgets
898
  outputs = reset_outputs()
899
 
900
- # function for submit button click
901
- submit_button.click(fn=variable_outputs, inputs=file_inputs, outputs=outputs)
902
 
903
- # function for clear button click
904
- # this only handles the outputs. Input reset is handled at button definition
905
- clear_button.click(fn=reset_outputs, inputs=[], outputs=outputs)
906
 
907
  # function for example files
908
- dataset.click(fn=process_examples, inputs=dataset, outputs=outputs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
909
 
910
 
911
  demo.launch(server_name="0.0.0.0")
 
151
  return img
152
 
153
 
154
+ def plot_bucket_fullness(driver_df, title):
155
+ # Determine required trust buckets
156
+ buckets = [
157
+ "Stability",
158
+ "Development",
159
+ "Relationship",
160
+ "Benefit",
161
+ "Vision",
162
+ "Competence",
163
+ ]
164
+
165
+ # Check if columns are present in df
166
+ missing_columns = [col for col in buckets if col not in driver_df.columns]
167
+
168
+ if missing_columns:
169
+ logging.warning(
170
+ f"The following columns are missing in driver_df: {missing_columns}"
171
+ )
172
+ return None
173
+ logging.info("All required columns are present in driver_df.")
174
+
175
+ color_map = {
176
+ "Stability": "#642b93",
177
+ "Development": "#e9e23e",
178
+ "Relationship": "#c52121",
179
+ "Benefit": "#049c54",
180
+ "Vision": "#f4672a",
181
+ "Competence": "#2e3094",
182
+ }
183
+
184
+ order = buckets
185
+
186
+ # Calculate the percentage of fullness for each column in buckets
187
+ results_df = (driver_df[buckets].mean()).reset_index()
188
+ results_df.columns = ["Trust_Bucket", "Fullness_of_Bucket"]
189
+ results_df["Trust_Bucket"] = pd.Categorical(
190
+ results_df["Trust_Bucket"], categories=order, ordered=True
191
+ )
192
+ results_df.sort_values("Trust_Bucket", inplace=True)
193
+
194
+ fig, ax = plt.subplots(figsize=(10, 8))
195
+
196
+ # formatter = FuncFormatter(lambda x, _: f"{x:.0f}%")
197
+ # ax.yaxis.set_major_formatter(formatter)
198
+
199
+ ax.bar(
200
+ results_df["Trust_Bucket"],
201
+ results_df["Fullness_of_Bucket"],
202
+ color=[color_map[bucket] for bucket in results_df["Trust_Bucket"]],
203
+ edgecolor="white",
204
+ zorder=2,
205
+ )
206
+
207
+ # Adding the percentage values on top of the bars
208
+ for i, row in enumerate(results_df.itertuples(index=False, name=None)):
209
+ trust_bucket, fullness_of_bucket = row
210
+ ax.text(
211
+ i,
212
+ fullness_of_bucket + 0.5, # slightly above the top of the bar
213
+ f"{fullness_of_bucket:.1f}",
214
+ ha="center",
215
+ va="bottom",
216
+ color="#8c8b8c",
217
+ )
218
+
219
+ y_max = results_df["Fullness_of_Bucket"].max() + 1
220
+ plt.ylim(0, y_max)
221
+ plt.ylabel("Fullness")
222
+ plt.title(title, fontsize=14)
223
+
224
+ ax.spines[["top", "right"]].set_color("none")
225
+
226
+ # Adding grey dotted lines along the y-axis labels
227
+ y_ticks = ax.get_yticks()
228
+ for y_tick in y_ticks:
229
+ ax.axhline(y=y_tick, color="grey", linestyle="--", linewidth=0.5, zorder=1)
230
+
231
+ ax.set_axisbelow(True)
232
+ plt.tight_layout()
233
+
234
+ # Save the figure to a bytes buffer and then to an image
235
+ img_data = io.BytesIO()
236
+ plt.savefig(img_data, format="png", facecolor=fig.get_facecolor(), edgecolor="none")
237
+ img_data.seek(0)
238
+ img = Image.open(img_data)
239
+ plt.close(fig)
240
+
241
+ return img
242
+
243
+
244
  def call_r_script(
245
  input_file,
246
  text_output_path,
 
342
  # Check if Driver and Builder sheets are present in the dataset
343
  trustbuilder_present = "Builder" in excel_file.sheet_names
344
 
 
 
 
345
  # Step 1: Check for missing columns and handle NPS column
346
  required_columns = [
347
  "Trust",
 
421
  with open(text_output_path, "r") as file:
422
  output_text = file.read()
423
 
424
+ # Get file name for display
425
+ file_name = file_path.split("/")[1]
426
+
427
+ # plot how full the trust buckets are
428
+ title = f"Trust Profile: {file_name}"
429
+ img_bucketfull = plot_bucket_fullness(df, title)
430
+
431
+ # plot trust
432
  # Get n_samples from output text
433
  n_samples_trust = output_text.split(": Trust")[1]
434
  n_samples_trust = n_samples_trust.split("Analysis based on ")[1]
 
441
  img_trust = plot_model_results(
442
  results_df_trust,
443
  average_value_trust,
444
+ # f"TrustLogic® Drivers\n(What drives your trust)\nn={n_samples_trust}",
445
+ f"Trust Drivers: {file_name}",
446
  "Trust",
447
  )
448
 
449
+ # plot NPS
450
  img_nps = None
451
  if nps_present:
452
  # Get n_samples from output text
 
460
  img_nps = plot_model_results(
461
  results_df_nps,
462
  average_value_nps,
463
+ # f"TrustLogic® Drivers\n(What drives your NPS)\nn={n_samples_nps}",
464
+ f"NPS Drivers: {file_name}",
465
  "NPS",
466
  )
467
 
468
+ # plot loyalty
469
  img_loyalty = None
470
  if loyalty_present:
471
  # Get n_samples from output text
 
481
  img_loyalty = plot_model_results(
482
  results_df_loyalty,
483
  average_value_loyalty,
484
+ # f"TrustLogic® Drivers\n(What drives your Loyalty)\nn={n_samples_loyalty}",
485
+ f"Loyalty Drivers: {file_name}",
486
  "Loyalty",
487
  )
488
 
489
+ # plot consideration
490
  img_consideration = None
491
  if consideration_present:
492
  # Get n_samples from output text
 
504
  img_consideration = plot_model_results(
505
  results_df_consideration,
506
  average_value_consideration,
507
+ # f"TrustLogic® Drivers\n(What drives your Consideration)\nn={n_samples_consideration}",
508
+ f"Consideration Drivers: {file_name}",
509
  "Consideration",
510
  )
511
 
512
+ # plot satisfaction
513
  img_satisfaction = None
514
  if satisfaction_present:
515
  # Get n_samples from output text
 
527
  img_satisfaction = plot_model_results(
528
  results_df_satisfaction,
529
  average_value_satisfaction,
530
+ # f"TrustLogic® Drivers\n(What drives your Satisfaction)\nn={n_samples_satisfaction}",
531
+ f"Satisfaction Drivers: {file_name}",
532
  "Satisfaction",
533
  )
534
 
535
+ # plot trust builder table 1 and 2
536
  df_builder = None
537
  df_builder_pivot = None
538
  if trustbuilder_present:
 
646
  )
647
 
648
  return (
649
+ img_bucketfull,
650
  img_trust,
651
  img_nps,
652
  img_loyalty,
 
675
  """
676
 
677
  # Process each file
678
+ img_bucketfull_list = []
679
  img_trust_list = []
680
  img_nps_list = []
681
  img_loyalty_list = []
 
687
 
688
  for file_path in file_paths:
689
  (
690
+ img_bucketfull,
691
  img_trust,
692
  img_nps,
693
  img_loyalty,
 
697
  df_builder_pivot,
698
  output_text,
699
  ) = analyze_excel_single(file_path)
700
+ img_bucketfull_list.append(img_bucketfull)
701
  img_trust_list.append(img_trust)
702
  img_nps_list.append(img_nps)
703
  img_loyalty_list.append(img_loyalty)
 
708
  output_text_list.append(output_text)
709
 
710
  return (
711
+ img_bucketfull_list,
712
  img_trust_list,
713
  img_nps_list,
714
  img_loyalty_list,
 
741
 
742
  # Call batch file processing and get analysis results
743
  (
744
+ img_bucketfull_list,
745
  img_trust_list,
746
  img_nps_list,
747
  img_loyalty_list,
 
760
 
761
  # Use zip_longest to iterate over the lists, padding with None
762
  for row, (
763
+ img_bucketfull,
764
  img_trust,
765
  img_nps,
766
  img_loyalty,
 
771
  output_text,
772
  ) in enumerate(
773
  zip_longest(
774
+ img_bucketfull_list,
775
  img_trust_list,
776
  img_nps_list,
777
  img_loyalty_list,
 
787
 
788
  # Based on the number of files uploaded, determine the content of each textbox
789
  plots = [
790
+ gr.Markdown(
791
+ "<span style='font-size:20px; font-weight:bold;'>1) Trust Profile</span>"
792
+ ),
793
+ gr.Markdown(
794
+ "This analysis shows you show strongly you are trusted in each of the six Trust Buckets®. You can also see this for any competitor."
795
+ ),
796
+ gr.Image(
797
+ value=img_bucketfull,
798
+ type="pil",
799
+ # label=f"{dataset_name}: Trust Drivers",
800
+ label="Trust Profile",
801
+ visible=True,
802
+ ),
803
+ gr.Markdown(
804
+ "<span style='font-size:20px; font-weight:bold;'>2) Trust and KPI Drivers</span>"
805
+ ),
806
+ gr.Markdown(
807
+ "This analysis shows you which of the TrustLogic® dimensions are most effective in building more trust and improving your KPIs. "
808
+ + "Here we display Trust and NPS, but in the full version you can include up to four KPIs (e.g. CSAT, Consideration, Loyalty). ​"
809
+ + "<br>The Trust Buckets® extending to the right are the more important ones. We show how they over and under-index. "
810
+ + "The average driver impact is 16.7% (100% divided by 6 trust dimensions). The higher the % above average, the more important. "
811
+ + "That means that you need to ‘fill’ these Trust Buckets® with the right attributes and messages."
812
+ ),
813
  gr.Image(
814
  value=img_trust,
815
  type="pil",
 
824
  label="NPS Drivers",
825
  visible=True,
826
  ),
827
+ gr.Image(
828
+ value=img_loyalty,
829
+ type="pil",
830
+ # label=f"{dataset_name}: Loyalty Drivers",
831
+ visible=True,
832
+ ),
833
+ gr.Image(
834
+ value=img_consideration,
835
+ type="pil",
836
+ # label=f"{dataset_name}: Consideration Drivers",
837
+ visible=True,
838
+ ),
839
+ gr.Image(
840
+ value=img_satisfaction,
841
+ type="pil",
842
+ # label=f"{dataset_name}: Satisfaction Drivers",
843
+ visible=True,
844
+ ),
845
+ gr.Textbox(
846
+ value=output_text,
847
+ # label=f"{dataset_name}: Analysis Summary",
848
+ visible=False,
849
+ ),
850
+ ]
851
+
852
+ # add current plots to container
853
+ plots_visible += plots
854
+
855
+ if isinstance(df_builder, pd.DataFrame) and isinstance(
856
+ df_builder_pivot, pd.DataFrame
857
+ ):
858
+ logging.debug(f"df_builder: {df_builder}")
859
+ logging.debug(f"df_builder_pivot: {df_builder_pivot}")
860
+
861
+ markdown_5 = gr.Markdown(
862
+ "<span style='font-size:20px; font-weight:bold;'>3) Proof Points</span>"
863
+ )
864
+ markdown_6 = gr.Markdown(
865
+ "These are the reasons to trust and recommend. They can be your brand values, features, attributes, programmes and messages. "
866
+ + "<br>In the first table, use the little arrow in each column to toggle the most to least effective proof points to fill each Trust Bucket®. Your focus is only on the Trust Bucket® with the highest driver impact. "
867
+ + "<br>In the second table you see the top scoring proof points ordered by Trust Bucket®."
868
+ )
869
+
870
+ table_builder_1 = gr.Dataframe(
871
  value=df_builder,
872
  headers=list(df_builder.columns),
873
  interactive=False,
 
875
  visible=True,
876
  height=800,
877
  wrap=True,
878
+ )
879
+ table_builder_2 = gr.Dataframe(
880
  value=df_builder_pivot,
881
  headers=list(df_builder_pivot.columns),
882
  interactive=False,
 
884
  visible=True,
885
  height=800,
886
  wrap=True,
887
+ )
 
888
 
889
+ # add builder tables to container
890
+ plots_visible.append(markdown_5)
891
+ plots_visible.append(markdown_6)
892
+ plots_visible.append(table_builder_1)
893
+ plots_visible.append(table_builder_2)
894
+ else:
895
+ # otherwise, add invisible tables
896
+ empty_markdown = gr.Markdown("", visible=False)
897
+ empty_table = gr.Dataframe(value=None, label=" ", visible=False)
898
+ plots_visible.append(empty_markdown)
899
+ plots_visible.append(empty_markdown)
900
+ plots_visible.append(empty_table)
901
+ plots_visible.append(empty_table)
902
 
903
  plots_invisible = [
904
+ gr.Markdown("", visible=False),
905
+ gr.Markdown("", visible=False),
906
+ gr.Image(label="Trust Buckets", visible=False),
907
+ gr.Markdown("", visible=False),
908
+ gr.Markdown("", visible=False),
 
909
  gr.Image(label="Trust Drivers", visible=False),
910
  gr.Image(label="NPS Drivers", visible=False),
911
+ gr.Image(label="Loyalty Drivers", visible=False),
912
+ gr.Image(label="Consideration Drivers", visible=False),
913
+ gr.Image(label="Satisfaction Drivers", visible=False),
914
+ gr.Textbox(label="Analysis Summary", visible=False),
915
+ gr.Markdown("", visible=False),
916
+ gr.Markdown("", visible=False),
917
+ gr.Dataframe(value=None, label=" ", visible=False),
918
+ gr.Dataframe(value=None, label=" ", visible=False),
919
  ]
920
 
921
  return plots_visible + plots_invisible * (max_outputs - k)
 
926
  outputs = []
927
 
928
  # Create fixed dummy components
929
+ markdown_1 = gr.Markdown(
930
+ "<span style='font-size:20px; font-weight:bold;'>1) Trust Profile</span>"
931
+ )
932
+ markdown_2 = gr.Markdown(
933
+ "This analysis shows you show strongly you are trusted in each of the six Trust Buckets®. You can also see this for any competitor."
934
+ )
935
+ buckets_plot = gr.Image(value=None, label="Trust Buckets", visible=True)
936
+
937
+ markdown_3 = gr.Markdown(
938
+ "<span style='font-size:20px; font-weight:bold;'>2) Trust and KPI Drivers</span>"
939
+ )
940
+ markdown_4 = gr.Markdown(
941
+ "This analysis shows you which of the TrustLogic® dimensions are most effective in building more trust and improving your KPIs. "
942
+ + "Here we display Trust and NPS, but in the full version you can include up to four KPIs (e.g. CSAT, Consideration, Loyalty). ​"
943
+ + "<br>The Trust Buckets® extending to the right are the more important ones. We show how they over and under-index. "
944
+ + "The average driver impact is 16.7% (100% divided by 6 trust dimensions). The higher the % above average, the more important. "
945
+ + "That means that you need to ‘fill’ these Trust Buckets® with the right attributes and messages."
946
+ )
947
  trust_plot = gr.Image(value=None, label="Trust Drivers", visible=True)
948
  nps_plot = gr.Image(value=None, label="NPS Drivers", visible=True)
949
+ loyalty_plot = gr.Image(value=None, label="Loyalty Drivers", visible=True)
950
+ consideration_plot = gr.Image(
951
+ value=None, label="Consideration Drivers", visible=True
952
+ )
953
+ satisfaction_plot = gr.Image(value=None, label="Satisfaction Drivers", visible=True)
954
+ summary_text = gr.Textbox(value=None, label="Analysis Summary", visible=False)
955
+
956
+ markdown_5 = gr.Markdown(
957
+ "<span style='font-size:20px; font-weight:bold;'>3) Proof Points</span>"
958
+ )
959
+ markdown_6 = gr.Markdown(
960
+ "These are the reasons to trust and recommend. They can be your brand values, features, attributes, programmes and messages. "
961
+ + "<br>In the first table, use the little arrow in each column to toggle the most to least effective proof points to fill each Trust Bucket®. Your focus is only on the Trust Bucket® with the highest driver impact. "
962
+ + "<br>In the second table you see the top scoring proof points ordered by Trust Bucket®."
963
+ )
964
+
965
  df_builder = gr.Dataframe(value=None, label=" ", visible=True)
966
  df_builder_pivot = gr.Dataframe(value=None, label=" ", visible=True)
967
+
968
+ outputs.append(markdown_1)
969
+ outputs.append(markdown_2)
970
+ outputs.append(buckets_plot)
971
+ outputs.append(markdown_3)
972
+ outputs.append(markdown_4)
973
  outputs.append(trust_plot)
974
  outputs.append(nps_plot)
975
+ outputs.append(loyalty_plot)
976
+ outputs.append(consideration_plot)
977
+ outputs.append(satisfaction_plot)
978
+ outputs.append(summary_text)
979
+ outputs.append(markdown_5)
980
+ outputs.append(markdown_6)
981
  outputs.append(df_builder)
982
  outputs.append(df_builder_pivot)
 
 
 
 
983
 
984
  # invisible from second set onwards
985
  for i in range(1, max_outputs):
986
+ markdown_empty = gr.Markdown("", visible=False)
987
+ plot_empty = gr.Image(value=None, label="", visible=False)
988
+ df_empty = gr.Dataframe(value=None, label=" ", visible=False)
989
+ text_empty = gr.Textbox(value=None, label="", visible=False)
990
+
991
+ outputs.append(markdown_empty)
992
+ outputs.append(markdown_empty)
993
+ outputs.append(plot_empty)
994
+ outputs.append(markdown_empty)
995
+ outputs.append(markdown_empty)
996
+ outputs.append(plot_empty)
997
+ outputs.append(plot_empty)
998
+ outputs.append(plot_empty)
999
+ outputs.append(plot_empty)
1000
+ outputs.append(plot_empty)
1001
+ outputs.append(text_empty)
1002
+ outputs.append(markdown_empty)
1003
+ outputs.append(markdown_empty)
1004
+ outputs.append(df_empty)
1005
+ outputs.append(df_empty)
 
 
 
 
1006
 
1007
  return outputs
1008
 
 
1011
  file_path = f"example_files/{file_name[0]}"
1012
  file_path = [file_path]
1013
  outputs = variable_outputs(file_path)
1014
+
1015
  return outputs
1016
 
1017
 
 
1062
  # dataset.click(fn=process_examples, inputs=dataset, outputs=outputs)
1063
 
1064
  with gr.Blocks() as demo:
1065
+ with gr.Column():
1066
+ # title = gr.Markdown("# TrustLogic & NPS Driver Analysis (Batch Version)")
1067
+ # description = gr.Markdown(instruction_text)
1068
+ gr.Markdown(
1069
+ "<span style='font-size:20px; font-weight:bold;'>Click 'Volkswagen Customers' or 'Volkswagen Prospects' to see the full results and play with the TrustAI.</span>"
1070
+ )
1071
+ gr.Markdown(
1072
+ "Our calculator will conduct the driver analysis from the underlying Excel file and display the results. "
1073
+ + "Scroll down to view them and interact with them. "
1074
+ + "In the full version you can link your survey directly to our calculator or export your data as CSV and drag & drop it into our calculator."
1075
+ )
1076
 
1077
  with gr.Column():
1078
  with gr.Row():
1079
+ # dataset_1 = gr.Dataset(
1080
+ # components=[gr.Textbox(visible=False)],
1081
+ # # label="Select an example to calculate the Trust Drivers from the underlying Excel files",
1082
+ # label="",
1083
+ # type="values",
1084
+ # samples=[
1085
+ # ["Volkswagen Customers.xlsx"],
1086
+ # ["Volkswagen Prospects.xlsx"],
1087
+ # ],
1088
+ # )
1089
+ vw_customers_btn = gr.Button("Volkswagen Customers")
1090
+ vw_prospects_btn = gr.Button("Volkswagen Prospects")
 
 
 
1091
 
1092
  with gr.Row():
1093
+ gr.Markdown(
1094
+ "<span style='font-size:20px; font-weight:bold;'>Click any of the examples below to see top-line driver results in different categories.</span>"
1095
+ )
1096
 
1097
  with gr.Row():
1098
+ # dataset_2 = gr.Dataset(
1099
+ # components=[gr.Textbox(visible=False)],
1100
+ # # label="Select an example to calculate the Trust Drivers from the underlying Excel files",
1101
+ # label="",
1102
+ # type="values",
1103
+ # samples=[
1104
+ # ["HSBC.xlsx"],
1105
+ # ["CBA.xlsx"],
1106
+ # ["BUPA.xlsx"],
1107
+ # ["Health Insurance.xlsx"],
1108
+ # ["Care.xlsx"],
1109
+ # ["WV.xlsx"],
1110
+ # ["Red Cross.xlsx"],
1111
+ # ],
1112
+ # )
1113
+
1114
+ hsbc_btn = gr.Button("HSBC")
1115
+ cba_btn = gr.Button("CBA")
1116
+ bupa_btn = gr.Button("BUPA")
1117
+ health_insurance_btn = gr.Button("Health Insurance")
1118
+ care_btn = gr.Button("Care")
1119
+ wv_btn = gr.Button("WV")
1120
+ red_cross_btn = gr.Button("Red Cross")
1121
+
1122
+ # with gr.Row():
1123
+ # # set file upload widget
1124
+ # file_inputs = gr.Files(label="Excel Dataset")
1125
+
1126
+ # with gr.Row():
1127
+ # # set clear and submit butttons
1128
+ # clear_button = gr.ClearButton(file_inputs)
1129
+ # submit_button = gr.Button("Submit", variant="primary")
1130
 
1131
  with gr.Column():
1132
  # set default output widgets
1133
  outputs = reset_outputs()
1134
 
1135
+ # # function for submit button click
1136
+ # submit_button.click(fn=variable_outputs, inputs=file_inputs, outputs=outputs)
1137
 
1138
+ # # function for clear button click
1139
+ # # this only handles the outputs. Input reset is handled at button definition
1140
+ # clear_button.click(fn=reset_outputs, inputs=[], outputs=outputs)
1141
 
1142
  # function for example files
1143
+ # dataset.click(fn=process_examples, inputs=dataset, outputs=outputs)
1144
+ # dataset_1.click(fn=process_examples, inputs=dataset_1, outputs=outputs)
1145
+ # dataset_2.click(fn=process_examples, inputs=dataset_2, outputs=outputs)
1146
+
1147
+ # Create gr.State components to store file names as lists
1148
+ vw_customers_state = gr.State(value=["Volkswagen Customers.xlsx"])
1149
+ vw_prospects_state = gr.State(value=["Volkswagen Prospects.xlsx"])
1150
+ hsbc_state = gr.State(value=["HSBC.xlsx"])
1151
+ cba_state = gr.State(value=["CBA.xlsx"])
1152
+ bupa_state = gr.State(value=["BUPA.xlsx"])
1153
+ health_insurance_state = gr.State(value=["Health Insurance.xlsx"])
1154
+ care_state = gr.State(value=["Care.xlsx"])
1155
+ wv_state = gr.State(value=["WV.xlsx"])
1156
+ red_cross_state = gr.State(value=["Red Cross.xlsx"])
1157
+
1158
+ vw_customers_btn.click(
1159
+ fn=process_examples,
1160
+ inputs=[vw_customers_state],
1161
+ outputs=outputs,
1162
+ )
1163
+ vw_prospects_btn.click(
1164
+ fn=process_examples,
1165
+ inputs=[vw_prospects_state],
1166
+ outputs=outputs,
1167
+ )
1168
+ hsbc_btn.click(
1169
+ fn=process_examples,
1170
+ inputs=[hsbc_state],
1171
+ outputs=outputs,
1172
+ )
1173
+ cba_btn.click(
1174
+ fn=process_examples,
1175
+ inputs=[cba_state],
1176
+ outputs=outputs,
1177
+ )
1178
+ bupa_btn.click(
1179
+ fn=process_examples,
1180
+ inputs=[bupa_state],
1181
+ outputs=outputs,
1182
+ )
1183
+ health_insurance_btn.click(
1184
+ fn=process_examples,
1185
+ inputs=[health_insurance_state],
1186
+ outputs=outputs,
1187
+ )
1188
+ care_btn.click(
1189
+ fn=process_examples,
1190
+ inputs=[care_state],
1191
+ outputs=outputs,
1192
+ )
1193
+ wv_btn.click(
1194
+ fn=process_examples,
1195
+ inputs=[wv_state],
1196
+ outputs=outputs,
1197
+ )
1198
+ red_cross_btn.click(
1199
+ fn=process_examples,
1200
+ inputs=[red_cross_state],
1201
+ outputs=outputs,
1202
+ )
1203
 
1204
 
1205
  demo.launch(server_name="0.0.0.0")
example_files/ANZ.xlsx CHANGED
Binary files a/example_files/ANZ.xlsx and b/example_files/ANZ.xlsx differ
 
example_files/BUPA.xlsx CHANGED
Binary files a/example_files/BUPA.xlsx and b/example_files/BUPA.xlsx differ
 
example_files/CBA.xlsx CHANGED
Binary files a/example_files/CBA.xlsx and b/example_files/CBA.xlsx differ
 
example_files/Care.xlsx CHANGED
Binary files a/example_files/Care.xlsx and b/example_files/Care.xlsx differ
 
example_files/HSBC.xlsx CHANGED
Binary files a/example_files/HSBC.xlsx and b/example_files/HSBC.xlsx differ
 
example_files/Health Insurance.xlsx CHANGED
Binary files a/example_files/Health Insurance.xlsx and b/example_files/Health Insurance.xlsx differ
 
example_files/Red Cross.xlsx CHANGED
Binary files a/example_files/Red Cross.xlsx and b/example_files/Red Cross.xlsx differ
 
example_files/Volkswagen Customers.xlsx ADDED
Binary file (20.1 kB). View file
 
example_files/Volkswagen Prospects.xlsx ADDED
Binary file (36 kB). View file
 
example_files/WV.xlsx CHANGED
Binary files a/example_files/WV.xlsx and b/example_files/WV.xlsx differ