Update app.py
Browse files
app.py
CHANGED
|
@@ -34,17 +34,25 @@ long_context_examples = [
|
|
| 34 |
"The cafe is experiencing a slow, quiet morning"]
|
| 35 |
]
|
| 36 |
|
| 37 |
-
def get_label_color(label):
|
| 38 |
-
"""Return color based on NLI label."""
|
| 39 |
-
|
| 40 |
-
'entailment': '
|
| 41 |
-
'neutral': '
|
| 42 |
-
'contradiction': '
|
| 43 |
}
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
def create_analysis_html(sentence_results, global_label):
|
| 47 |
-
"""Create HTML table for sentence analysis with color coding."""
|
| 48 |
html = """
|
| 49 |
<style>
|
| 50 |
.analysis-table {
|
|
@@ -67,13 +75,18 @@ def create_analysis_html(sentence_results, global_label):
|
|
| 67 |
border-radius: 5px;
|
| 68 |
font-weight: bold;
|
| 69 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
</style>
|
| 71 |
"""
|
| 72 |
|
| 73 |
-
# Add global prediction box
|
| 74 |
html += f"""
|
| 75 |
-
<div class="global-prediction" style="background-color: {get_label_color(global_label)}">
|
| 76 |
-
Global Prediction: {global_label}
|
|
|
|
| 77 |
</div>
|
| 78 |
"""
|
| 79 |
|
|
@@ -83,15 +96,17 @@ def create_analysis_html(sentence_results, global_label):
|
|
| 83 |
<tr>
|
| 84 |
<th>Sentence</th>
|
| 85 |
<th>Prediction</th>
|
|
|
|
| 86 |
</tr>
|
| 87 |
"""
|
| 88 |
|
| 89 |
# Add rows for each sentence
|
| 90 |
for result in sentence_results:
|
| 91 |
html += f"""
|
| 92 |
-
<tr style="background-color: {get_label_color(result['prediction'])}">
|
| 93 |
<td>{result['sentence']}</td>
|
| 94 |
<td>{result['prediction']}</td>
|
|
|
|
| 95 |
</tr>
|
| 96 |
"""
|
| 97 |
|
|
|
|
| 34 |
"The cafe is experiencing a slow, quiet morning"]
|
| 35 |
]
|
| 36 |
|
| 37 |
+
def get_label_color(label, confidence=1.0):
|
| 38 |
+
"""Return color based on NLI label with confidence-based saturation."""
|
| 39 |
+
base_colors = {
|
| 40 |
+
'entailment': 'rgb(144, 238, 144)', # Light green
|
| 41 |
+
'neutral': 'rgb(255, 229, 180)', # Peach
|
| 42 |
+
'contradiction': 'rgb(255, 182, 193)' # Light pink
|
| 43 |
}
|
| 44 |
+
|
| 45 |
+
# Convert RGB color to RGBA with confidence-based alpha
|
| 46 |
+
if label in base_colors:
|
| 47 |
+
rgb = base_colors[label].replace('rgb(', '').replace(')', '').split(',')
|
| 48 |
+
r, g, b = map(int, rgb)
|
| 49 |
+
# Adjust the color based on confidence
|
| 50 |
+
alpha = 0.3 + (0.7 * confidence) # Range from 0.3 to 1.0
|
| 51 |
+
return f"rgba({r},{g},{b},{alpha})"
|
| 52 |
+
return '#FFFFFF'
|
| 53 |
|
| 54 |
+
def create_analysis_html(sentence_results, global_label, global_confidence):
|
| 55 |
+
"""Create HTML table for sentence analysis with color coding and confidence."""
|
| 56 |
html = """
|
| 57 |
<style>
|
| 58 |
.analysis-table {
|
|
|
|
| 75 |
border-radius: 5px;
|
| 76 |
font-weight: bold;
|
| 77 |
}
|
| 78 |
+
.confidence {
|
| 79 |
+
font-size: 0.9em;
|
| 80 |
+
color: #666;
|
| 81 |
+
}
|
| 82 |
</style>
|
| 83 |
"""
|
| 84 |
|
| 85 |
+
# Add global prediction box with confidence
|
| 86 |
html += f"""
|
| 87 |
+
<div class="global-prediction" style="background-color: {get_label_color(global_label, global_confidence)}">
|
| 88 |
+
Global Prediction: {global_label}
|
| 89 |
+
<span class="confidence">(Confidence: {global_confidence:.2%})</span>
|
| 90 |
</div>
|
| 91 |
"""
|
| 92 |
|
|
|
|
| 96 |
<tr>
|
| 97 |
<th>Sentence</th>
|
| 98 |
<th>Prediction</th>
|
| 99 |
+
<th>Confidence</th>
|
| 100 |
</tr>
|
| 101 |
"""
|
| 102 |
|
| 103 |
# Add rows for each sentence
|
| 104 |
for result in sentence_results:
|
| 105 |
html += f"""
|
| 106 |
+
<tr style="background-color: {get_label_color(result['prediction'], result['confidence'])}">
|
| 107 |
<td>{result['sentence']}</td>
|
| 108 |
<td>{result['prediction']}</td>
|
| 109 |
+
<td>{result['confidence']:.2%}</td>
|
| 110 |
</tr>
|
| 111 |
"""
|
| 112 |
|