Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
| 2561 |
-
|
| 2562 |
-
|
| 2563 |
-
|
| 2564 |
-
|
| 2565 |
-
|
| 2566 |
-
|
| 2567 |
-
|
| 2568 |
-
|
| 2569 |
-
|
| 2570 |
-
|
| 2571 |
-
|
| 2572 |
-
|
| 2573 |
-
|
| 2574 |
-
|
| 2575 |
-
|
| 2576 |
-
|
| 2577 |
-
|
| 2578 |
-
|
| 2579 |
-
|
| 2580 |
-
|
| 2581 |
-
|
| 2582 |
-
|
| 2583 |
-
|
| 2584 |
-
|
| 2585 |
-
|
| 2586 |
-
|
| 2587 |
-
|
| 2588 |
-
|
| 2589 |
-
|
| 2590 |
-
|
| 2591 |
-
|
| 2592 |
-
|
| 2593 |
-
|
| 2594 |
-
|
| 2595 |
-
|
| 2596 |
-
|
| 2597 |
-
|
| 2598 |
-
|
| 2599 |
-
|
| 2600 |
-
|
| 2601 |
-
|
| 2602 |
-
|
| 2603 |
-
|
| 2604 |
-
|
| 2605 |
-
|
| 2606 |
-
|
| 2607 |
-
|
| 2608 |
-
|
| 2609 |
-
|
| 2610 |
-
|
| 2611 |
-
|
| 2612 |
-
|
| 2613 |
-
|
| 2614 |
-
|
| 2615 |
-
|
| 2616 |
-
|
| 2617 |
-
|
| 2618 |
-
|
| 2619 |
-
|
| 2620 |
-
|
| 2621 |
-
|
| 2622 |
-
|
| 2623 |
-
|
| 2624 |
-
|
| 2625 |
-
|
| 2626 |
-
|
| 2627 |
-
|
| 2628 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2629 |
|
| 2630 |
-
|
| 2631 |
|
| 2632 |
-
|
| 2633 |
-
|
| 2634 |
-
|
| 2635 |
-
|
| 2636 |
-
|
| 2637 |
-
|
| 2638 |
-
|
| 2639 |
-
|
| 2640 |
-
|
| 2641 |
-
|
| 2642 |
-
|
| 2643 |
-
|
| 2644 |
-
|
| 2645 |
-
|
| 2646 |
-
|
| 2647 |
-
|
| 2648 |
-
|
| 2649 |
-
|
| 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 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|