Spaces:
Running
Running
update figures
Browse files
app.py
CHANGED
@@ -618,29 +618,27 @@ def create_detailed_safety_breakdown(category_data, selected_models):
|
|
618 |
# Process data for each model
|
619 |
# Reverse the order to match the appearance in your screenshot
|
620 |
for model in selected_models[::-1]:
|
621 |
-
# Calculate overall scores across all categories
|
|
|
|
|
|
|
|
|
622 |
total_safe = 0
|
623 |
total_slightly = 0
|
624 |
total_moderately = 0
|
625 |
total_extremely = 0
|
626 |
-
total_categories = len(category_data["categories"])
|
627 |
|
628 |
-
for category in
|
629 |
model_data = category_data["categories"][category][model]
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
# Calculate averages
|
636 |
-
safe_ratio = total_safe / total_categories
|
637 |
-
slightly_ratio = total_slightly / total_categories
|
638 |
-
moderately_ratio = total_moderately / total_categories
|
639 |
-
extremely_ratio = total_extremely / total_categories
|
640 |
|
641 |
# Add trace for each model with segments for each safety status
|
642 |
fig.add_trace(go.Scatter(
|
643 |
-
x=[0,
|
644 |
y=[model, model, model, model, model],
|
645 |
mode='lines',
|
646 |
line=dict(
|
@@ -653,7 +651,7 @@ def create_detailed_safety_breakdown(category_data, selected_models):
|
|
653 |
# Add colored segments for each safety status
|
654 |
# Safe segment
|
655 |
fig.add_trace(go.Scatter(
|
656 |
-
x=[0,
|
657 |
y=[model, model],
|
658 |
mode='lines',
|
659 |
line=dict(width=50, color=color_map["Safe"]), # Reduced width
|
@@ -663,7 +661,7 @@ def create_detailed_safety_breakdown(category_data, selected_models):
|
|
663 |
|
664 |
# Slightly Unsafe segment
|
665 |
fig.add_trace(go.Scatter(
|
666 |
-
x=[
|
667 |
y=[model, model],
|
668 |
mode='lines',
|
669 |
line=dict(width=50, color=color_map["Slightly Unsafe"]), # Reduced width
|
@@ -673,7 +671,7 @@ def create_detailed_safety_breakdown(category_data, selected_models):
|
|
673 |
|
674 |
# Moderately Unsafe segment
|
675 |
fig.add_trace(go.Scatter(
|
676 |
-
x=[
|
677 |
y=[model, model],
|
678 |
mode='lines',
|
679 |
line=dict(width=50, color=color_map["Moderately Unsafe"]), # Reduced width
|
@@ -683,7 +681,7 @@ def create_detailed_safety_breakdown(category_data, selected_models):
|
|
683 |
|
684 |
# Extremely Unsafe segment
|
685 |
fig.add_trace(go.Scatter(
|
686 |
-
x=[
|
687 |
y=[model, model],
|
688 |
mode='lines',
|
689 |
line=dict(width=50, color=color_map["Extremely Unsafe"]), # Reduced width
|
|
|
618 |
# Process data for each model
|
619 |
# Reverse the order to match the appearance in your screenshot
|
620 |
for model in selected_models[::-1]:
|
621 |
+
# Calculate overall scores across all categories using weighted average
|
622 |
+
categories = list(category_data["categories"].keys())
|
623 |
+
category_weights = [category_data["categories"][category]["total"] for category in categories]
|
624 |
+
total_examples = sum(category_weights)
|
625 |
+
|
626 |
total_safe = 0
|
627 |
total_slightly = 0
|
628 |
total_moderately = 0
|
629 |
total_extremely = 0
|
|
|
630 |
|
631 |
+
for i, category in enumerate(categories):
|
632 |
model_data = category_data["categories"][category][model]
|
633 |
+
weight = category_weights[i] / total_examples
|
634 |
+
total_safe += model_data["safe"] * weight
|
635 |
+
total_slightly += model_data["slightly unsafe"] * weight
|
636 |
+
total_moderately += model_data["moderately unsafe"] * weight
|
637 |
+
total_extremely += model_data["extremely unsafe"] * weight
|
|
|
|
|
|
|
|
|
|
|
638 |
|
639 |
# Add trace for each model with segments for each safety status
|
640 |
fig.add_trace(go.Scatter(
|
641 |
+
x=[0, total_safe, total_safe + total_slightly, total_safe + total_slightly + total_moderately, 1],
|
642 |
y=[model, model, model, model, model],
|
643 |
mode='lines',
|
644 |
line=dict(
|
|
|
651 |
# Add colored segments for each safety status
|
652 |
# Safe segment
|
653 |
fig.add_trace(go.Scatter(
|
654 |
+
x=[0, total_safe],
|
655 |
y=[model, model],
|
656 |
mode='lines',
|
657 |
line=dict(width=50, color=color_map["Safe"]), # Reduced width
|
|
|
661 |
|
662 |
# Slightly Unsafe segment
|
663 |
fig.add_trace(go.Scatter(
|
664 |
+
x=[total_safe, total_safe + total_slightly],
|
665 |
y=[model, model],
|
666 |
mode='lines',
|
667 |
line=dict(width=50, color=color_map["Slightly Unsafe"]), # Reduced width
|
|
|
671 |
|
672 |
# Moderately Unsafe segment
|
673 |
fig.add_trace(go.Scatter(
|
674 |
+
x=[total_safe + total_slightly, total_safe + total_slightly + total_moderately],
|
675 |
y=[model, model],
|
676 |
mode='lines',
|
677 |
line=dict(width=50, color=color_map["Moderately Unsafe"]), # Reduced width
|
|
|
681 |
|
682 |
# Extremely Unsafe segment
|
683 |
fig.add_trace(go.Scatter(
|
684 |
+
x=[total_safe + total_slightly + total_moderately, 1],
|
685 |
y=[model, model],
|
686 |
mode='lines',
|
687 |
line=dict(width=50, color=color_map["Extremely Unsafe"]), # Reduced width
|