Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
|
@@ -815,31 +815,67 @@ def create_statistics_dashboard(df: pd.DataFrame) -> Tuple[str, go.Figure]:
|
|
| 815 |
|
| 816 |
html_parts.append('</div>')
|
| 817 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 818 |
# Create distribution charts
|
| 819 |
fig = make_subplots(rows=1, cols=2,
|
| 820 |
-
subplot_titles=("Probability Delta Distribution",
|
| 821 |
|
| 822 |
-
|
|
|
|
| 823 |
fig.add_trace(
|
| 824 |
-
go.Histogram(x=df['prob_delta'], nbinsx=30, name="Prob Delta",
|
| 825 |
marker_color='#6366f1'),
|
| 826 |
row=1, col=1
|
| 827 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 828 |
|
|
|
|
| 829 |
if 'sentence_category' in df.columns:
|
| 830 |
category_counts = df['sentence_category'].value_counts()
|
| 831 |
fig.add_trace(
|
| 832 |
-
go.Bar(x=category_counts.index, y=category_counts.values, name="Categories",
|
| 833 |
marker_color='#22c55e'),
|
| 834 |
row=1, col=2
|
| 835 |
)
|
| 836 |
elif 'reasoning_pattern' in df.columns:
|
| 837 |
pattern_counts = df['reasoning_pattern'].value_counts()
|
| 838 |
fig.add_trace(
|
| 839 |
-
go.Bar(x=pattern_counts.index, y=pattern_counts.values, name="Patterns",
|
| 840 |
marker_color='#22c55e'),
|
| 841 |
row=1, col=2
|
| 842 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 843 |
|
| 844 |
fig.update_layout(
|
| 845 |
template="plotly_dark",
|
|
|
|
| 815 |
|
| 816 |
html_parts.append('</div>')
|
| 817 |
|
| 818 |
+
# Determine what to show in second chart
|
| 819 |
+
second_chart_title = "Category Distribution"
|
| 820 |
+
if 'sentence_category' in df.columns:
|
| 821 |
+
second_chart_title = "Sentence Category"
|
| 822 |
+
elif 'reasoning_pattern' in df.columns:
|
| 823 |
+
second_chart_title = "Reasoning Pattern"
|
| 824 |
+
elif 'task_type' in df.columns:
|
| 825 |
+
second_chart_title = "Task Type"
|
| 826 |
+
elif 'is_positive' in df.columns:
|
| 827 |
+
second_chart_title = "Positive vs Negative"
|
| 828 |
+
|
| 829 |
# Create distribution charts
|
| 830 |
fig = make_subplots(rows=1, cols=2,
|
| 831 |
+
subplot_titles=("Probability Delta Distribution", second_chart_title))
|
| 832 |
|
| 833 |
+
# First chart: Probability Delta histogram
|
| 834 |
+
if 'prob_delta' in df.columns and len(df['prob_delta'].dropna()) > 0:
|
| 835 |
fig.add_trace(
|
| 836 |
+
go.Histogram(x=df['prob_delta'].dropna(), nbinsx=30, name="Prob Delta",
|
| 837 |
marker_color='#6366f1'),
|
| 838 |
row=1, col=1
|
| 839 |
)
|
| 840 |
+
else:
|
| 841 |
+
# Fallback: show prob_before/prob_after if available
|
| 842 |
+
if 'prob_after' in df.columns:
|
| 843 |
+
fig.add_trace(
|
| 844 |
+
go.Histogram(x=df['prob_after'].dropna(), nbinsx=30, name="Prob After",
|
| 845 |
+
marker_color='#6366f1'),
|
| 846 |
+
row=1, col=1
|
| 847 |
+
)
|
| 848 |
|
| 849 |
+
# Second chart: Categories, patterns, or task types
|
| 850 |
if 'sentence_category' in df.columns:
|
| 851 |
category_counts = df['sentence_category'].value_counts()
|
| 852 |
fig.add_trace(
|
| 853 |
+
go.Bar(x=category_counts.index.tolist(), y=category_counts.values.tolist(), name="Categories",
|
| 854 |
marker_color='#22c55e'),
|
| 855 |
row=1, col=2
|
| 856 |
)
|
| 857 |
elif 'reasoning_pattern' in df.columns:
|
| 858 |
pattern_counts = df['reasoning_pattern'].value_counts()
|
| 859 |
fig.add_trace(
|
| 860 |
+
go.Bar(x=pattern_counts.index.tolist(), y=pattern_counts.values.tolist(), name="Patterns",
|
| 861 |
marker_color='#22c55e'),
|
| 862 |
row=1, col=2
|
| 863 |
)
|
| 864 |
+
elif 'task_type' in df.columns:
|
| 865 |
+
task_counts = df['task_type'].value_counts()
|
| 866 |
+
fig.add_trace(
|
| 867 |
+
go.Bar(x=task_counts.index.tolist(), y=task_counts.values.tolist(), name="Task Types",
|
| 868 |
+
marker_color='#22c55e'),
|
| 869 |
+
row=1, col=2
|
| 870 |
+
)
|
| 871 |
+
elif 'is_positive' in df.columns:
|
| 872 |
+
pos_neg_counts = df['is_positive'].value_counts()
|
| 873 |
+
labels = ['Positive' if v else 'Negative' for v in pos_neg_counts.index.tolist()]
|
| 874 |
+
fig.add_trace(
|
| 875 |
+
go.Bar(x=labels, y=pos_neg_counts.values.tolist(), name="Impact",
|
| 876 |
+
marker_color=['#22c55e' if l == 'Positive' else '#ef4444' for l in labels]),
|
| 877 |
+
row=1, col=2
|
| 878 |
+
)
|
| 879 |
|
| 880 |
fig.update_layout(
|
| 881 |
template="plotly_dark",
|