Spaces:
Running
Running
devjas1
commited on
Commit
·
2fb5cb5
1
Parent(s):
8b601a3
(FEAT): Add utilities for confidence calculation and visualization
Browse files- Implement `calculate_softmax_confidence` to compute probabilities, max confidence, and confidence levels using softmax.
- Add `get_confidence_badge` for generating emoji and level descriptions based on confidence values.
- Create `format_confidence_display` for formatting confidence strings for UI.
- Add `create_confidence_progress_html` to generate HTML-based progress bars for confidence breakdown.
- Include `calculate_legacy_confidence` for backward compatibility with margin-based confidence calculations.
- Provide color-coded and visually appealing confidence indicators for better user experience.
- utils/confidence.py +18 -18
utils/confidence.py
CHANGED
@@ -100,25 +100,25 @@ def create_confidence_progress_html(
|
|
100 |
color = "#e5e7eb" # gray-200
|
101 |
text_color = "#6b7280" # gray-500
|
102 |
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
</div>
|
123 |
</div>
|
124 |
</div>
|
|
|
100 |
color = "#e5e7eb" # gray-200
|
101 |
text_color = "#6b7280" # gray-500
|
102 |
|
103 |
+
percentage = prob * 100
|
104 |
|
105 |
+
html_parts.append(f"""
|
106 |
+
<div style="margin-bottom: 8px;">
|
107 |
+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px;">
|
108 |
+
<span style="font-size: 0.875rem; font-weight: 500; color: #374151;">{label}</span>
|
109 |
+
<span style="font-size: 0.875rem; color: #6b7280;">{percentage:.1f}%</span>
|
110 |
+
</div>
|
111 |
+
<div style="width: 100%; background-color: #f3f4f6; border-radius: 0.375rem; height: 20px; overflow: hidden;">
|
112 |
+
<div style="
|
113 |
+
width: {percentage}%;
|
114 |
+
height: 100%;
|
115 |
+
background-color: {color};
|
116 |
+
display: flex;
|
117 |
+
align-items: center;
|
118 |
+
justify-content: center;
|
119 |
+
transition: width 0.3s ease;
|
120 |
+
">
|
121 |
+
{f'<span style="color: {text_color}; font-size: 0.75rem; font-weight: 600;">{percentage:.1f}%</span>' if percentage > 20 else ''}
|
122 |
</div>
|
123 |
</div>
|
124 |
</div>
|