UMCU commited on
Commit
c2e82c6
·
verified ·
1 Parent(s): 5255e37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
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
- Hex color string (e.g., "#00FF00")
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 f"#{r:02x}{g:02x}{b:02x}"
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 = token.replace("</w>", "").replace("##", "").strip()
 
 
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({perplexity_to_color(perp, min_perp=1, max_perp=VIZ_SETTINGS['max_perplexity_display'])}, {bg_alpha}); "
446
  f"color: #000; "
447
  f"padding: 2px 4px; "
448
  f"margin: 1px; "
449
  f"border-radius: 3px; "
450
- f"border: 1px solid rgba({perplexity_to_color(perp, min_perp=1, max_perp=VIZ_SETTINGS['max_perplexity_display'])}, {border_alpha}); "
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;"