Wajahat698 commited on
Commit
df05c7f
·
verified ·
1 Parent(s): 17c5594

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -27
app.py CHANGED
@@ -2426,6 +2426,7 @@ def load_nps_and_r2(file_path):
2426
 
2427
  return nps_img, r2_img
2428
 
 
2429
  with gr.Blocks(css=css, js=js_func) as demo:
2430
  gr.HTML("""
2431
  <style>
@@ -2438,11 +2439,11 @@ with gr.Blocks(css=css, js=js_func) as demo:
2438
  </style>
2439
  """)
2440
 
2441
- # 🔁 States (moved to top)
2442
  vw_customers_state11 = gr.State(value=["example_files/VW Owners.xlsx"])
2443
  vw_prospects_state12 = gr.State(value=["example_files/Volkswagen Non Customers.xlsx"])
2444
- vw_customers_state = gr.State(value=["VW Owners.xlsx"])
2445
- vw_prospects_state = gr.State(value=["Volkswagen Non Customers.xlsx"])
2446
  selected_dataset_ai = gr.State(value="VW Owners.xlsx")
2447
  chat_history = gr.State(value=[])
2448
  data_visible_state = gr.State(value=False)
@@ -2463,7 +2464,7 @@ with gr.Blocks(css=css, js=js_func) as demo:
2463
  vw_customers_btn = gr.Button("VW Owners", elem_id="vw_customers_btn")
2464
  vw_prospects_btn = gr.Button("VW Prospects", elem_id="vw_prospects_btn")
2465
 
2466
- # 🧠 Chat section (moved to top)
2467
  with gr.Column(elem_id="chat_container"):
2468
  prompt_textbox = gr.Textbox(value=predefined_prompt, scale=4, label="Insert your prompt", visible=True)
2469
  submit_button = gr.Button("Submit")
@@ -2493,9 +2494,37 @@ with gr.Blocks(css=css, js=js_func) as demo:
2493
  gr.Markdown("""<div style='text-align: center;'><h3>How much of your NPS is determined by TrustLogic®</h3></div>""")
2494
  trust_r2_img = gr.HTML()
2495
 
2496
- # Create placeholder components for dynamic outputs
2497
- with gr.Column() as dynamic_outputs_container:
2498
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2499
 
2500
  # Show/hide data section functionality
2501
  def toggle_data_section(visible):
@@ -2529,32 +2558,32 @@ with gr.Blocks(css=css, js=js_func) as demo:
2529
  outputs=trust_score_output,
2530
  )
2531
 
2532
- # Modified to handle component rendering
2533
- @gr.render(inputs=[vw_customers_state, vw_prospects_state, selected_dataset_ai], triggers=[vw_customers_btn.click, vw_prospects_btn.click, demo.load])
2534
- def render_dynamic_outputs(vw_cust_state, vw_pros_state, selected_dataset):
2535
- # Determine which dataset to use
2536
- if selected_dataset == "VW Owners.xlsx":
2537
- file_inputs = vw_cust_state
2538
- else:
2539
- file_inputs = vw_pros_state
2540
-
2541
- # Get the components from variable_outputs
2542
- output_components = variable_outputs(file_inputs)
2543
-
2544
- # Render the components
2545
- with gr.Column():
2546
- for component in output_components:
2547
- if component is not None and hasattr(component, 'render'):
2548
- component.render()
2549
 
 
 
 
2550
  vw_customers_btn.click(
2551
- fn=lambda: "VW Owners.xlsx",
2552
  inputs=[],
2553
  outputs=selected_dataset_ai
2554
  )
2555
 
2556
  vw_prospects_btn.click(
2557
- fn=lambda: "Volkswagen Non Customers.xlsx",
2558
  inputs=[],
2559
  outputs=selected_dataset_ai
2560
  )
@@ -2582,9 +2611,16 @@ with gr.Blocks(css=css, js=js_func) as demo:
2582
  inputs=[],
2583
  outputs=trust_score_output
2584
  )
 
 
 
 
 
 
2585
 
2586
  try:
2587
  demo.launch(server_name="0.0.0.0")
2588
  except Exception as e:
2589
  logger.error(f"Error launching Gradio app: {e}")
2590
- raise e
 
 
2426
 
2427
  return nps_img, r2_img
2428
 
2429
+
2430
  with gr.Blocks(css=css, js=js_func) as demo:
2431
  gr.HTML("""
2432
  <style>
 
2439
  </style>
2440
  """)
2441
 
2442
+ # 🔁 States
2443
  vw_customers_state11 = gr.State(value=["example_files/VW Owners.xlsx"])
2444
  vw_prospects_state12 = gr.State(value=["example_files/Volkswagen Non Customers.xlsx"])
2445
+ vw_customers_state = gr.State(value=["VW Owners.xlsx"]) # Just the filename
2446
+ vw_prospects_state = gr.State(value=["Volkswagen Non Customers.xlsx"]) # Just the filename
2447
  selected_dataset_ai = gr.State(value="VW Owners.xlsx")
2448
  chat_history = gr.State(value=[])
2449
  data_visible_state = gr.State(value=False)
 
2464
  vw_customers_btn = gr.Button("VW Owners", elem_id="vw_customers_btn")
2465
  vw_prospects_btn = gr.Button("VW Prospects", elem_id="vw_prospects_btn")
2466
 
2467
+ # 🧠 Chat section
2468
  with gr.Column(elem_id="chat_container"):
2469
  prompt_textbox = gr.Textbox(value=predefined_prompt, scale=4, label="Insert your prompt", visible=True)
2470
  submit_button = gr.Button("Submit")
 
2494
  gr.Markdown("""<div style='text-align: center;'><h3>How much of your NPS is determined by TrustLogic®</h3></div>""")
2495
  trust_r2_img = gr.HTML()
2496
 
2497
+ # Move outputs components inside data_section
2498
+ markdown_3 = gr.Markdown(visible=True)
2499
+ markdown_4 = gr.Markdown(visible=True)
2500
+ trust_plot = gr.Image(value=None, label="Trust Drivers", visible=True)
2501
+ nps_plot = gr.Image(value=None, label="NPS Drivers", visible=True)
2502
+ loyalty_plot = gr.Image(value=None, label="Loyalty Drivers", visible=True)
2503
+ consideration_plot = gr.Image(value=None, label="Consideration Drivers", visible=True)
2504
+ satisfaction_plot = gr.Image(value=None, label="Satisfaction Drivers", visible=True)
2505
+ summary_text = gr.Textbox(value=None, label="Analysis Summary", visible=True)
2506
+ markdown_5 = gr.Markdown(visible=True)
2507
+ markdown_6 = gr.Markdown(visible=True)
2508
+ df_builder_pivot = gr.Dataframe(value=None, label="", visible=True)
2509
+
2510
+ # Create outputs list for functions
2511
+ outputs = [
2512
+ markdown_3, markdown_4, trust_plot, nps_plot, loyalty_plot,
2513
+ consideration_plot, satisfaction_plot, summary_text,
2514
+ markdown_5, markdown_6, df_builder_pivot
2515
+ ]
2516
+
2517
+ # Modified process_examples to return values
2518
+ def process_examples_values(file_name):
2519
+ output_components = process_examples(file_name)
2520
+ # Extract values from components
2521
+ values = []
2522
+ for comp in output_components[:11]: # Only first 11 components
2523
+ if hasattr(comp, 'value'):
2524
+ values.append(comp.value)
2525
+ else:
2526
+ values.append(None)
2527
+ return values
2528
 
2529
  # Show/hide data section functionality
2530
  def toggle_data_section(visible):
 
2558
  outputs=trust_score_output,
2559
  )
2560
 
2561
+ vw_customers_btn.click(
2562
+ fn=process_examples_values,
2563
+ inputs=[vw_customers_state],
2564
+ outputs=outputs,
2565
+ )
2566
+
2567
+ vw_prospects_btn.click(
2568
+ fn=process_examples_values,
2569
+ inputs=[vw_prospects_state],
2570
+ outputs=outputs,
2571
+ )
2572
+
2573
+ def set_vw_owners():
2574
+ return "VW Owners.xlsx"
 
 
 
2575
 
2576
+ def set_vw_prospects():
2577
+ return "Volkswagen Non Customers.xlsx"
2578
+
2579
  vw_customers_btn.click(
2580
+ fn=set_vw_owners,
2581
  inputs=[],
2582
  outputs=selected_dataset_ai
2583
  )
2584
 
2585
  vw_prospects_btn.click(
2586
+ fn=set_vw_prospects,
2587
  inputs=[],
2588
  outputs=selected_dataset_ai
2589
  )
 
2611
  inputs=[],
2612
  outputs=trust_score_output
2613
  )
2614
+
2615
+ demo.load(
2616
+ fn=process_examples_values,
2617
+ inputs=[vw_customers_state],
2618
+ outputs=outputs
2619
+ )
2620
 
2621
  try:
2622
  demo.launch(server_name="0.0.0.0")
2623
  except Exception as e:
2624
  logger.error(f"Error launching Gradio app: {e}")
2625
+ raise e
2626
+