Wajahat698 commited on
Commit
d25177f
·
verified ·
1 Parent(s): 233b711

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -7
app.py CHANGED
@@ -66,6 +66,78 @@ selected_dataset_ai = "Volkswagen Customers"
66
  df_builder_pivot_str = ""
67
 
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  def plot_model_results(results_df, average_value, title, model_type):
70
  """
71
  Plot model results with specific orders and colors for Trust and NPS models.
@@ -516,20 +588,20 @@ def analyze_excel_single(file_path):
516
 
517
  # plot trust
518
  # Get n_samples from output text
519
- n_samples_trust = output_text.split(": Trust")[1]
520
  n_samples_trust = n_samples_trust.split("Analysis based on ")[1]
521
  n_samples_trust = n_samples_trust.split("observations")[0]
522
 
523
- results_df_trust = None
524
  results_df_trust = pd.read_csv(csv_output_path_trust)
525
  results_df_trust["Importance_percent"] = results_df_trust["Importance"] * 100
526
  average_value_trust = results_df_trust["Importance_percent"].mean()
527
-
528
- img_trust = plot_model_results(
 
 
529
  results_df_trust,
530
- average_value_trust,
531
- f"Trust Drivers: {file_name}",
532
- "Trust",
533
  )
534
  display_trust_score_1()
535
 
 
66
  df_builder_pivot_str = ""
67
 
68
 
69
+ def plot_bucket_fullness(driver_df, title):
70
+ # Set image path
71
+ image_path = "./images/image.png"
72
+
73
+ # Load background image
74
+ try:
75
+ img = Image.open(image_path)
76
+ except FileNotFoundError:
77
+ raise FileNotFoundError(f"❌ Error: Background image '{image_path}' not found!")
78
+
79
+ # Trust categories (fixed order)
80
+ categories = [
81
+ "Vision Trust", "Development Trust", "Benefit Trust",
82
+ "Competence Trust", "Stability Trust", "Relationship Trust"
83
+ ]
84
+
85
+ # Extract fullness values from the DataFrame
86
+ percentages = driver_df.mean().tolist()
87
+
88
+ # Colors for each bubble
89
+ colors = ["#DF8859", "#E3B05B", "#418387", "#6D93AB", "#375570", "#C63F48"]
90
+
91
+ # Bubble positions (aligned with background)
92
+ bubble_positions = [
93
+ (0.66, 1.20), # Vision (moved up)
94
+ (1.4, -0.10), # Development
95
+ (0.66, -1.10), # Benefit
96
+ (-0.70, -1.20), # Competence
97
+ (-1.35, 0.0), # Stability
98
+ (-0.70, 1.15) # Relationship (shifted left)
99
+ ]
100
+
101
+ # Scale bubble sizes dynamically based on fullness values
102
+ max_size = 0.35 # Maximum bubble size
103
+ min_size = 0.18 # Minimum bubble size
104
+ min_value, max_value = min(percentages), max(percentages)
105
+
106
+ # Normalize values to fit in the bubble size range
107
+ bubble_sizes = [
108
+ min_size + (max_size - min_size) * ((p - min_value) / (max_value - min_value + 1e-5))
109
+ for p in percentages
110
+ ]
111
+
112
+ # Create the figure
113
+ fig, ax = plt.subplots(figsize=(8, 8))
114
+ ax.set_xlim(-2, 2)
115
+ ax.set_ylim(-2, 2)
116
+ ax.axis("off")
117
+
118
+ # Display background image
119
+ ax.imshow(img, extent=[-1.5, 1.5, -1.5, 1.5])
120
+
121
+ # Draw bubbles with dynamically scaled sizes
122
+ for i, (x, y) in enumerate(bubble_positions):
123
+ size = bubble_sizes[i]
124
+ circle = patches.Circle((x, y), size, facecolor=colors[i], alpha=1.0, lw=1.5)
125
+ ax.add_patch(circle)
126
+
127
+ # **Add percentage inside the bubble**
128
+ ax.text(
129
+ x, y, f"{percentages[i]:.1f}%", fontsize=12, fontweight="bold",
130
+ ha="center", va="center", color="white"
131
+ )
132
+
133
+ # Save plot to a buffer
134
+ img_buffer = io.BytesIO()
135
+ plt.savefig(img_buffer, format="png", bbox_inches="tight", facecolor=fig.get_facecolor())
136
+ img_buffer.seek(0)
137
+ plt.close(fig)
138
+
139
+ # Convert to PIL Image for Gradio display
140
+ return Image.open(img_buffer)
141
  def plot_model_results(results_df, average_value, title, model_type):
142
  """
143
  Plot model results with specific orders and colors for Trust and NPS models.
 
588
 
589
  # plot trust
590
  # Get n_samples from output text
591
+ n n_samples_trust = output_text.split(": Trust")[1]
592
  n_samples_trust = n_samples_trust.split("Analysis based on ")[1]
593
  n_samples_trust = n_samples_trust.split("observations")[0]
594
 
595
+
596
  results_df_trust = pd.read_csv(csv_output_path_trust)
597
  results_df_trust["Importance_percent"] = results_df_trust["Importance"] * 100
598
  average_value_trust = results_df_trust["Importance_percent"].mean()
599
+
600
+ # Instead of calling plot_model_results for Trust Drivers,
601
+ # call the separate bubble plot function:
602
+ img_trust = plot_trust_driver_bubbles(
603
  results_df_trust,
604
+ f"Trust Drivers: {file_name}"
 
 
605
  )
606
  display_trust_score_1()
607