Wajahat698 commited on
Commit
f177fd2
·
verified ·
1 Parent(s): 95adada

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +167 -168
app.py CHANGED
@@ -2554,180 +2554,179 @@ def load_nps_and_r2(file_path):
2554
 
2555
 
2556
 
2557
-
2558
-
2559
  with gr.Blocks(css=css, js=js_func) as demo:
2560
- gr.HTML("""
2561
- <style>
2562
- #trust_driver_img, #nps_driver_img {
2563
- display: inline-block;
2564
- width: 49%;
2565
- margin-right: 1%;
2566
- vertical-align: top;
2567
- }
2568
- </style>
2569
- """)
2570
-
2571
- # Title and intro
2572
- with gr.Column():
2573
- gr.Markdown("""
2574
- <h2 style="text-align: center; font-size: 2.25rem; font-weight: 600;">
2575
- TrustLogic AI Demo
2576
- </h2>
2577
- """)
2578
- gr.Markdown("### Experience TrustLogic AI")
2579
- gr.Markdown("Experience how quick and easy it is to build the right trust based on insight with our TrustLogic AI")
2580
-
2581
- # Dataset selection buttons
2582
- with gr.Column():
2583
- with gr.Row():
2584
- vw_customers_btn = gr.Button("VW Owners", elem_id="vw_customers_btn")
2585
- vw_prospects_btn = gr.Button("VW Prospects", elem_id="vw_prospects_btn")
2586
-
2587
- # 🧠 Chat section (moved to top)
2588
- with gr.Column(elem_id="chat_container"):
2589
- prompt_textbox = gr.Textbox(value=predefined_prompt, scale=4, label="Insert your prompt", visible=True)
2590
- submit_button = gr.Button("Submit")
2591
- bot = gr.Chatbot(placeholder=placeholder_text)
2592
-
2593
- # Button to show data
2594
- show_data_btn = gr.Button("Show the data", variant="primary", size="lg")
2595
-
2596
- # Data analysis section (initially hidden)
2597
- with gr.Column(visible=False) as data_section:
2598
- gr.Markdown("### Uncover the underlying data used for the prompt")
2599
- gr.Markdown("Quickly identify what drives your NPS and trust across different segments using the automated analyser.")
2600
- gr.Markdown("""
2601
- <span style="font-size:15px;">Volkswagen Example</span><br>
2602
- As a default, the analysis displays <strong>Volkswagen Owner</strong> results.
2603
- To trigger the analysis for <strong>Prospects</strong>, toggle to 'VW Prospects'.
2604
- """)
2605
-
2606
- with gr.Row(equal_height=True):
2607
- with gr.Column(scale=1):
2608
- nps_img_output = gr.HTML()
2609
-
2610
-
2611
-
2612
- with gr.Column(scale=1):
2613
- trust_score_output = gr.HTML()
2614
-
2615
- with gr.Column(scale=1):
2616
- gr.Markdown("""<div style='text-align: center;'><h3>How much of your NPS is determined by TrustLogic®</h3></div>""")
2617
- trust_r2_img = gr.HTML()
2618
-
2619
-
2620
- with gr.Column():
2621
- outputs = reset_outputs()
2622
-
2623
- # 🔁 States
2624
- vw_customers_state11 = gr.State(value=["example_files/VW Owners.xlsx"])
2625
- vw_prospects_state12 = gr.State(value=["example_files/Volkswagen Non Customers.xlsx"])
2626
- vw_customers_state = gr.State(value=["VW Owners.xlsx"])
2627
- vw_prospects_state = gr.State(value=["Volkswagen Non Customers.xlsx"])
2628
- selected_dataset_ai = gr.State(value="VW Owners.xlsx") # Matches dictionary key
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2629
 
2630
- chat_history = gr.State(value=[])
2631
 
2632
- # Show/hide data section functionality
2633
- data_visible_state = gr.State(value=False)
2634
-
2635
- def toggle_data_section(visible):
2636
- new_visible = not visible
2637
- button_text = "Hide the data" if new_visible else "Show the data"
2638
- return gr.Column.update(visible=new_visible), button_text, new_visible
2639
-
2640
- show_data_btn.click(
2641
- fn=toggle_data_section,
2642
- inputs=data_visible_state,
2643
- outputs=[data_section, show_data_btn, data_visible_state]
2644
- )
2645
-
2646
- submit_button.click(
2647
- fn=chatbot_response,
2648
- inputs=[prompt_textbox, chat_history, selected_dataset_ai],
2649
- outputs=[bot, chat_history]
2650
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2651
 
 
 
 
 
 
2652
 
2653
 
2654
- ## All widget functions here ##
2655
 
2656
- vw_customers_btn.click(
2657
- fn=display_trust_score_1,
2658
- inputs=[],
2659
- outputs=trust_score_output,
2660
- )
2661
-
2662
- vw_prospects_btn.click(
2663
- fn=display_trust_score_2,
2664
- inputs=[],
2665
- outputs=trust_score_output,
2666
- )
2667
-
2668
- vw_customers_btn.click(
2669
- fn=process_examples,
2670
- inputs=[vw_customers_state],
2671
- outputs= outputs,
2672
- )
2673
-
2674
- vw_prospects_btn.click(
2675
- fn=process_examples,
2676
- inputs=[vw_prospects_state],
2677
- outputs= outputs,
2678
- )
2679
- def set_vw_owners():
2680
- return "VW Owners.xlsx"
2681
-
2682
- def set_vw_prospects():
2683
- return "Volkswagen Non Customers.xlsx"
2684
 
2685
-
2686
- vw_customers_btn.click(
2687
- fn=set_vw_owners,
2688
- inputs=[],
2689
- outputs=selected_dataset_ai
2690
- )
2691
-
2692
- vw_prospects_btn.click(
2693
- fn=set_vw_prospects,
2694
- inputs=[],
2695
- outputs=selected_dataset_ai
2696
- )
2697
- vw_customers_btn.click(
2698
- fn=lambda f: vwload_nps_and_r2(f[0]),
2699
- inputs=[vw_customers_state11],
2700
- outputs=[nps_img_output, trust_r2_img],
2701
- )
2702
-
2703
- vw_prospects_btn.click(
2704
- fn=lambda f: load_nps_and_r2(f[0]),
2705
- inputs=[vw_prospects_state12],
2706
- outputs=[nps_img_output, trust_r2_img],
2707
- )
2708
 
2709
-
2710
- demo.load(
2711
- fn=lambda f: vwload_nps_and_r2(f[0]),
2712
- inputs=[vw_customers_state11],
2713
- outputs=[nps_img_output, trust_r2_img],
2714
- )
2715
- demo.load(
2716
- fn=display_trust_score_1,
2717
- inputs=[],
2718
- outputs=trust_score_output
2719
- )
2720
-
2721
- demo.load(
2722
- fn=process_examples,
2723
- inputs=[vw_customers_state],
2724
- outputs=outputs
2725
- )
2726
-
2727
- try:
2728
- demo.launch(server_name="0.0.0.0")
2729
- except Exception as e:
2730
- logger.error(f"Error launching Gradio app: {e}")
2731
- raise e
2732
-
2733
-
 
2554
 
2555
 
2556
 
 
 
2557
  with gr.Blocks(css=css, js=js_func) as demo:
2558
+ gr.HTML("""
2559
+ <style>
2560
+ #trust_driver_img, #nps_driver_img {
2561
+ display: inline-block;
2562
+ width: 49%;
2563
+ margin-right: 1%;
2564
+ vertical-align: top;
2565
+ }
2566
+ </style>
2567
+ """)
2568
+
2569
+ # Title and intro
2570
+ with gr.Column():
2571
+ gr.Markdown("""
2572
+ <h2 style="text-align: center; font-size: 2.25rem; font-weight: 600;">
2573
+ TrustLogic AI Demo
2574
+ </h2>
2575
+ """)
2576
+ gr.Markdown("### Experience TrustLogic AI")
2577
+ gr.Markdown("Experience how quick and easy it is to build the right trust based on insight with our TrustLogic AI")
2578
+
2579
+ # Dataset selection buttons
2580
+ with gr.Column():
2581
+ with gr.Row():
2582
+ vw_customers_btn = gr.Button("VW Owners", elem_id="vw_customers_btn")
2583
+ vw_prospects_btn = gr.Button("VW Prospects", elem_id="vw_prospects_btn")
2584
+
2585
+ # 🧠 Chat section (moved to top)
2586
+ with gr.Column(elem_id="chat_container"):
2587
+ prompt_textbox = gr.Textbox(value=predefined_prompt, scale=4, label="Insert your prompt", visible=True)
2588
+ submit_button = gr.Button("Submit")
2589
+ bot = gr.Chatbot(placeholder=placeholder_text)
2590
+
2591
+ # Button to show data
2592
+ show_data_btn = gr.Button("Show the data", variant="primary", size="lg")
2593
+
2594
+ # Data analysis section (initially hidden)
2595
+ with gr.Column(visible=False) as data_section:
2596
+ gr.Markdown("### Uncover the underlying data used for the prompt")
2597
+ gr.Markdown("Quickly identify what drives your NPS and trust across different segments using the automated analyser.")
2598
+ gr.Markdown("""
2599
+ <span style="font-size:15px;">Volkswagen Example</span><br>
2600
+ As a default, the analysis displays <strong>Volkswagen Owner</strong> results.
2601
+ To trigger the analysis for <strong>Prospects</strong>, toggle to 'VW Prospects'.
2602
+ """)
2603
+
2604
+ with gr.Row(equal_height=True):
2605
+ with gr.Column(scale=1):
2606
+ nps_img_output = gr.HTML()
2607
+
2608
+ with gr.Column(scale=1):
2609
+ trust_score_output = gr.HTML()
2610
+
2611
+ with gr.Column(scale=1):
2612
+ gr.Markdown("""<div style='text-align: center;'><h3>How much of your NPS is determined by TrustLogic®</h3></div>""")
2613
+ trust_r2_img = gr.HTML()
2614
+
2615
+ with gr.Column():
2616
+ outputs = reset_outputs()
2617
+
2618
+ # 🔁 States - MOVED OUTSIDE OF DATA SECTION
2619
+ vw_customers_state11 = gr.State(value=["example_files/VW Owners.xlsx"])
2620
+ vw_prospects_state12 = gr.State(value=["example_files/Volkswagen Non Customers.xlsx"])
2621
+ vw_customers_state = gr.State(value=["VW Owners.xlsx"])
2622
+ vw_prospects_state = gr.State(value=["Volkswagen Non Customers.xlsx"])
2623
+ selected_dataset_ai = gr.State(value="VW Owners.xlsx") # ✅ Matches dictionary key
2624
+ chat_history = gr.State(value=[])
2625
+
2626
+ # Show/hide data section functionality
2627
+ data_visible_state = gr.State(value=False)
2628
+
2629
+ def toggle_data_section(visible):
2630
+ new_visible = not visible
2631
+ button_text = "Hide the data" if new_visible else "Show the data"
2632
+ return gr.update(visible=new_visible), button_text, new_visible
2633
+
2634
+ def set_vw_owners():
2635
+ return "VW Owners.xlsx"
2636
+
2637
+ def set_vw_prospects():
2638
+ return "Volkswagen Non Customers.xlsx"
2639
+
2640
+ # Event handlers - MOVED OUTSIDE OF DATA SECTION
2641
+ show_data_btn.click(
2642
+ fn=toggle_data_section,
2643
+ inputs=data_visible_state,
2644
+ outputs=[data_section, show_data_btn, data_visible_state]
2645
+ )
2646
+
2647
+ submit_button.click(
2648
+ fn=chatbot_response,
2649
+ inputs=[prompt_textbox, chat_history, selected_dataset_ai],
2650
+ outputs=[bot, chat_history]
2651
+ )
2652
 
2653
+ ## All widget functions here ##
2654
 
2655
+ vw_customers_btn.click(
2656
+ fn=display_trust_score_1,
2657
+ inputs=[],
2658
+ outputs=trust_score_output,
2659
+ )
2660
+
2661
+ vw_prospects_btn.click(
2662
+ fn=display_trust_score_2,
2663
+ inputs=[],
2664
+ outputs=trust_score_output,
2665
+ )
2666
+
2667
+ vw_customers_btn.click(
2668
+ fn=process_examples,
2669
+ inputs=[vw_customers_state],
2670
+ outputs=outputs,
2671
+ )
2672
+
2673
+ vw_prospects_btn.click(
2674
+ fn=process_examples,
2675
+ inputs=[vw_prospects_state],
2676
+ outputs=outputs,
2677
+ )
2678
+
2679
+ vw_customers_btn.click(
2680
+ fn=set_vw_owners,
2681
+ inputs=[],
2682
+ outputs=selected_dataset_ai
2683
+ )
2684
+
2685
+ vw_prospects_btn.click(
2686
+ fn=set_vw_prospects,
2687
+ inputs=[],
2688
+ outputs=selected_dataset_ai
2689
+ )
2690
+
2691
+ vw_customers_btn.click(
2692
+ fn=lambda f: vwload_nps_and_r2(f[0]),
2693
+ inputs=[vw_customers_state11],
2694
+ outputs=[nps_img_output, trust_r2_img],
2695
+ )
2696
+
2697
+ vw_prospects_btn.click(
2698
+ fn=lambda f: load_nps_and_r2(f[0]),
2699
+ inputs=[vw_prospects_state12],
2700
+ outputs=[nps_img_output, trust_r2_img],
2701
+ )
2702
+
2703
+ # Load functions for initial state
2704
+ demo.load(
2705
+ fn=lambda f: vwload_nps_and_r2(f[0]),
2706
+ inputs=[vw_customers_state11],
2707
+ outputs=[nps_img_output, trust_r2_img],
2708
+ )
2709
+
2710
+ demo.load(
2711
+ fn=display_trust_score_1,
2712
+ inputs=[],
2713
+ outputs=trust_score_output
2714
+ )
2715
+
2716
+ demo.load(
2717
+ fn=process_examples,
2718
+ inputs=[vw_customers_state],
2719
+ outputs=outputs
2720
+ )
2721
 
2722
+ try:
2723
+ demo.launch(server_name="0.0.0.0")
2724
+ except Exception as e:
2725
+ logger.error(f"Error launching Gradio app: {e}")
2726
+ raise e
2727
 
2728
 
 
2729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2730
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2731
 
2732
+