Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -325,7 +325,7 @@ def perplexity_to_color(perplexity, min_perp=1, max_perp=1000):
|
|
| 325 |
max_perp: Maximum perplexity (maps to red)
|
| 326 |
|
| 327 |
Returns:
|
| 328 |
-
|
| 329 |
"""
|
| 330 |
# Clamp perplexity to range
|
| 331 |
perp = max(min_perp, min(max_perp, perplexity))
|
|
@@ -356,7 +356,7 @@ def perplexity_to_color(perplexity, min_perp=1, max_perp=1000):
|
|
| 356 |
g = int(255 * (1 - factor))
|
| 357 |
b = 0
|
| 358 |
|
| 359 |
-
return
|
| 360 |
|
| 361 |
|
| 362 |
def create_visualization(tokens, perplexities):
|
|
@@ -390,7 +390,9 @@ def create_visualization(tokens, perplexities):
|
|
| 390 |
continue
|
| 391 |
|
| 392 |
# Clean token for display
|
| 393 |
-
clean_token =
|
|
|
|
|
|
|
| 394 |
if not clean_token:
|
| 395 |
continue
|
| 396 |
|
|
@@ -439,15 +441,20 @@ def create_visualization(tokens, perplexities):
|
|
| 439 |
bg_alpha = VIZ_SETTINGS["color_scheme"].get("background_alpha", 0.7)
|
| 440 |
border_alpha = VIZ_SETTINGS["color_scheme"].get("border_alpha", 0.9)
|
| 441 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
# Create colored span with tooltip
|
| 443 |
html_parts.append(
|
| 444 |
f'<span style="'
|
| 445 |
-
f"background-color: rgba({
|
| 446 |
f"color: #000; "
|
| 447 |
f"padding: 2px 4px; "
|
| 448 |
f"margin: 1px; "
|
| 449 |
f"border-radius: 3px; "
|
| 450 |
-
f"border: 1px solid rgba({
|
| 451 |
f"font-weight: 500; "
|
| 452 |
f"cursor: help; "
|
| 453 |
f"display: inline-block;"
|
|
|
|
| 325 |
max_perp: Maximum perplexity (maps to red)
|
| 326 |
|
| 327 |
Returns:
|
| 328 |
+
Tuple of (r, g, b) values as integers (0-255)
|
| 329 |
"""
|
| 330 |
# Clamp perplexity to range
|
| 331 |
perp = max(min_perp, min(max_perp, perplexity))
|
|
|
|
| 356 |
g = int(255 * (1 - factor))
|
| 357 |
b = 0
|
| 358 |
|
| 359 |
+
return (r, g, b)
|
| 360 |
|
| 361 |
|
| 362 |
def create_visualization(tokens, perplexities):
|
|
|
|
| 390 |
continue
|
| 391 |
|
| 392 |
# Clean token for display
|
| 393 |
+
clean_token = (
|
| 394 |
+
token.replace("</w>", "").replace("##", "").replace("Ġ", "").strip()
|
| 395 |
+
)
|
| 396 |
if not clean_token:
|
| 397 |
continue
|
| 398 |
|
|
|
|
| 441 |
bg_alpha = VIZ_SETTINGS["color_scheme"].get("background_alpha", 0.7)
|
| 442 |
border_alpha = VIZ_SETTINGS["color_scheme"].get("border_alpha", 0.9)
|
| 443 |
|
| 444 |
+
# Get RGB color from perplexity
|
| 445 |
+
r, g, b = perplexity_to_color(
|
| 446 |
+
perp, min_perp=1, max_perp=VIZ_SETTINGS["max_perplexity_display"]
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
# Create colored span with tooltip
|
| 450 |
html_parts.append(
|
| 451 |
f'<span style="'
|
| 452 |
+
f"background-color: rgba({r}, {g}, {b}, {bg_alpha}); "
|
| 453 |
f"color: #000; "
|
| 454 |
f"padding: 2px 4px; "
|
| 455 |
f"margin: 1px; "
|
| 456 |
f"border-radius: 3px; "
|
| 457 |
+
f"border: 1px solid rgba({r}, {g}, {b}, {border_alpha}); "
|
| 458 |
f"font-weight: 500; "
|
| 459 |
f"cursor: help; "
|
| 460 |
f"display: inline-block;"
|