Wajahat698 commited on
Commit
305f8a3
·
verified ·
1 Parent(s): 7834b54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -33
app.py CHANGED
@@ -2551,6 +2551,7 @@ def load_nps_and_r2(file_path):
2551
 
2552
  return nps_img, r2_img
2553
 
 
2554
  with gr.Blocks(css=css, js=js_func) as demo:
2555
  gr.HTML("""
2556
  <style>
@@ -2609,11 +2610,8 @@ with gr.Blocks(css=css, js=js_func) as demo:
2609
  gr.Markdown("""<div style='text-align: center;'><h3>How much of your NPS is determined by TrustLogic®</h3></div>""")
2610
  trust_r2_img = gr.HTML()
2611
 
2612
- # ADD THE MISSING OUTPUTS SECTION HERE
2613
  with gr.Column():
2614
- # Create all the output components that variable_outputs() expects
2615
- outputs = []
2616
-
2617
  # Trust and NPS Drivers section
2618
  markdown_3 = gr.Markdown(
2619
  "<span style='font-size:20px; font-weight:bold;'>Trust and NPS Drivers</span>",
@@ -2621,13 +2619,19 @@ with gr.Blocks(css=css, js=js_func) as demo:
2621
  )
2622
  markdown_4 = gr.Markdown(
2623
  """
2624
- This analysis shows which Trust Buckets® are most effective in building trust and improving your key performance indicators (KPIs).
2625
- <br><br>
2626
- The middle line is the average importance. The bars extending to the right show which Trust Buckets® are most important. The higher the percentage, the more important the Trust Bucket® is to your audience.
2627
  """,
2628
  visible=True,
2629
  )
2630
- trust_plot = gr.Image(value=None, label="Trust Drivers", visible=False)
 
 
 
 
 
 
 
 
2631
  nps_plot = gr.Image(value=None, label="NPS Drivers", visible=False)
2632
  loyalty_plot = gr.Image(value=None, label="Loyalty Drivers", visible=False)
2633
  consideration_plot = gr.Image(value=None, label="Consideration Drivers", visible=False)
@@ -2636,32 +2640,27 @@ with gr.Blocks(css=css, js=js_func) as demo:
2636
 
2637
  # TrustBuilders section
2638
  markdown_5 = gr.Markdown(
2639
- "<span style='font-size:20px; font-weight:bold;'>TrustBuilders®",
2640
  visible=True,
2641
  )
2642
  markdown_6 = gr.Markdown(
2643
- "These are the specific reasons to trust and recommend. They can be your brand values, features, attributes, programs, and messages. "
2644
- + "<br>For practical purposes, they tell you exactly what to do and say to build more trust and improve your KPIs. "
2645
- + "<br>In the table, use the little arrows to toggle by Trust Bucket® or Trust Builder® importance. "
2646
- + "<br>Tip: Compare Owners and Prospects. Even though some of the Trust Buckets® are the same, the Trust Builders® are very different.",
2647
  visible=True,
2648
  )
2649
- df_builder_pivot = gr.Dataframe(value=None, label="", visible=True)
2650
 
2651
- # Collect outputs in the correct order
2652
  outputs = [
2653
- markdown_3, markdown_4, trust_plot, nps_plot, loyalty_plot,
2654
  consideration_plot, satisfaction_plot, summary_text,
2655
  markdown_5, markdown_6, df_builder_pivot
2656
  ]
2657
 
2658
- # 🔁 States - FIXED FILE PATHS
2659
  vw_customers_state11 = gr.State(value=["example_files/VW Owners.xlsx"])
2660
  vw_prospects_state12 = gr.State(value=["example_files/Volkswagen Non Customers.xlsx"])
2661
- # ✅ FIXED: Added proper file paths
2662
  vw_customers_state = gr.State(value=["example_files/VW Owners.xlsx"])
2663
  vw_prospects_state = gr.State(value=["example_files/Volkswagen Non Customers.xlsx"])
2664
- # ✅ FIXED: Added proper file path for AI dataset selection
2665
  selected_dataset_ai = gr.State(value="example_files/VW Owners.xlsx")
2666
  chat_history = gr.State(value=[])
2667
 
@@ -2674,24 +2673,64 @@ with gr.Blocks(css=css, js=js_func) as demo:
2674
  return gr.update(visible=new_visible), button_text, new_visible
2675
 
2676
  def set_vw_owners():
2677
- return "example_files/VW Owners.xlsx" # ✅ FIXED: Added proper path
2678
 
2679
  def set_vw_prospects():
2680
- return "example_files/Volkswagen Non Customers.xlsx" # ✅ FIXED: Added proper path
2681
 
2682
- # MODIFIED process_examples function to work with your outputs
2683
  def process_examples_wrapper(file_inputs):
2684
  try:
2685
- # Call your existing variable_outputs function
2686
- result = variable_outputs(file_inputs)
2687
- # Return only the first 11 items to match your outputs list
2688
- return result[:11]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2689
  except Exception as e:
2690
  logger.error(f"Error in process_examples_wrapper: {e}")
2691
- # Return empty/default values for all outputs
2692
- return [
2693
- gr.update(visible=False) for _ in range(11)
2694
- ]
2695
 
2696
  # Event handlers
2697
  show_data_btn.click(
@@ -2781,6 +2820,3 @@ except Exception as e:
2781
 
2782
 
2783
 
2784
-
2785
-
2786
-
 
2551
 
2552
  return nps_img, r2_img
2553
 
2554
+
2555
  with gr.Blocks(css=css, js=js_func) as demo:
2556
  gr.HTML("""
2557
  <style>
 
2610
  gr.Markdown("""<div style='text-align: center;'><h3>How much of your NPS is determined by TrustLogic®</h3></div>""")
2611
  trust_r2_img = gr.HTML()
2612
 
2613
+ # CREATE THE OUTPUT COMPONENTS THAT MATCH variable_outputs() STRUCTURE
2614
  with gr.Column():
 
 
 
2615
  # Trust and NPS Drivers section
2616
  markdown_3 = gr.Markdown(
2617
  "<span style='font-size:20px; font-weight:bold;'>Trust and NPS Drivers</span>",
 
2619
  )
2620
  markdown_4 = gr.Markdown(
2621
  """
2622
+ The analysis identifies the TrustLogic® dimensions that are most effective in driving your audience's likelihood to recommend and trust you
 
 
2623
  """,
2624
  visible=True,
2625
  )
2626
+
2627
+ # Combined Trust + NPS Drivers Image
2628
+ combined_drivers_img = gr.Image(
2629
+ value=None,
2630
+ label="Trust + NPS Drivers",
2631
+ visible=True,
2632
+ )
2633
+
2634
+ # Individual driver images (mostly hidden)
2635
  nps_plot = gr.Image(value=None, label="NPS Drivers", visible=False)
2636
  loyalty_plot = gr.Image(value=None, label="Loyalty Drivers", visible=False)
2637
  consideration_plot = gr.Image(value=None, label="Consideration Drivers", visible=False)
 
2640
 
2641
  # TrustBuilders section
2642
  markdown_5 = gr.Markdown(
2643
+ "<span style='font-size:20px; font-weight:bold;'>What to say and do to build your trust and Net Promoter Score</span>",
2644
  visible=True,
2645
  )
2646
  markdown_6 = gr.Markdown(
2647
+ "<span style='font-size:17px; font-weight:bold;'>The features and messages that improve your NPS and trust most effectively. The key ones are marked in bold.</span>",
 
 
 
2648
  visible=True,
2649
  )
2650
+ df_builder_pivot = gr.Dataframe(value=None, label="", visible=True, height=800, wrap=True)
2651
 
2652
+ # Collect outputs in the correct order to match variable_outputs()
2653
  outputs = [
2654
+ markdown_3, markdown_4, combined_drivers_img, nps_plot, loyalty_plot,
2655
  consideration_plot, satisfaction_plot, summary_text,
2656
  markdown_5, markdown_6, df_builder_pivot
2657
  ]
2658
 
2659
+ # 🔁 States
2660
  vw_customers_state11 = gr.State(value=["example_files/VW Owners.xlsx"])
2661
  vw_prospects_state12 = gr.State(value=["example_files/Volkswagen Non Customers.xlsx"])
 
2662
  vw_customers_state = gr.State(value=["example_files/VW Owners.xlsx"])
2663
  vw_prospects_state = gr.State(value=["example_files/Volkswagen Non Customers.xlsx"])
 
2664
  selected_dataset_ai = gr.State(value="example_files/VW Owners.xlsx")
2665
  chat_history = gr.State(value=[])
2666
 
 
2673
  return gr.update(visible=new_visible), button_text, new_visible
2674
 
2675
  def set_vw_owners():
2676
+ return "example_files/VW Owners.xlsx"
2677
 
2678
  def set_vw_prospects():
2679
+ return "example_files/Volkswagen Non Customers.xlsx"
2680
 
2681
+ # MODIFIED wrapper function to extract VALUES from variable_outputs()
2682
  def process_examples_wrapper(file_inputs):
2683
  try:
2684
+ # Call batch file processing directly to get the data
2685
+ (
2686
+ img_bucketfull_list,
2687
+ img_trust_list,
2688
+ img_nps_list,
2689
+ img_loyalty_list,
2690
+ img_consideration_list,
2691
+ img_satisfaction_list,
2692
+ df_builder_pivot_list,
2693
+ output_text_list,
2694
+ ) = batch_file_processing(file_inputs)
2695
+
2696
+ # Process the first dataset (since we're only showing one at a time)
2697
+ if len(file_inputs) > 0:
2698
+ img_trust = img_trust_list[0] if img_trust_list else None
2699
+ img_nps = img_nps_list[0] if img_nps_list else None
2700
+ df_builder_pivot = df_builder_pivot_list[0] if df_builder_pivot_list else None
2701
+ output_text = output_text_list[0] if output_text_list else ""
2702
+
2703
+ # Create combined image
2704
+ combined_img = None
2705
+ if img_trust is not None and img_nps is not None:
2706
+ combined_img = combine_two_images_horizontally(img_trust, "Trust Drivers", img_nps, "NPS Drivers")
2707
+
2708
+ # Prepare dataframe for display
2709
+ styled_df = None
2710
+ if isinstance(df_builder_pivot, pd.DataFrame):
2711
+ styled_df = df_builder_pivot.style.apply(bold_high_impact_row, axis=1)
2712
+
2713
+ # Return updates for all components
2714
+ return [
2715
+ gr.update(value="<span style='font-size:20px; font-weight:bold;'>Trust and NPS Drivers</span>", visible=True),
2716
+ gr.update(value="The analysis identifies the TrustLogic® dimensions that are most effective in driving your audience's likelihood to recommend and trust you", visible=True),
2717
+ gr.update(value=combined_img, visible=True),
2718
+ gr.update(visible=False), # nps_plot
2719
+ gr.update(visible=False), # loyalty_plot
2720
+ gr.update(visible=False), # consideration_plot
2721
+ gr.update(visible=False), # satisfaction_plot
2722
+ gr.update(value=output_text, visible=False), # summary_text
2723
+ gr.update(value="<span style='font-size:20px; font-weight:bold;'>What to say and do to build your trust and Net Promoter Score</span>", visible=True),
2724
+ gr.update(value="<span style='font-size:17px; font-weight:bold;'>The features and messages that improve your NPS and trust most effectively. The key ones are marked in bold.</span>", visible=True),
2725
+ gr.update(value=styled_df, visible=True)
2726
+ ]
2727
+ else:
2728
+ # Return empty updates if no files
2729
+ return [gr.update() for _ in range(11)]
2730
+
2731
  except Exception as e:
2732
  logger.error(f"Error in process_examples_wrapper: {e}")
2733
+ return [gr.update() for _ in range(11)]
 
 
 
2734
 
2735
  # Event handlers
2736
  show_data_btn.click(
 
2820
 
2821
 
2822