#!/usr/bin/env python3
"""
Simple test to verify color visualization is working (no external dependencies)
"""
def test_color_html():
"""Test the HTML color generation without imports"""
print("šØ Testing Color HTML Generation")
print("=" * 50)
# Simple test data
tokens = ["The", "quick", "brown", "fox"]
perplexities = [1.2, 5.8, 12.3, 2.1]
# Manual color generation test (similar to app logic)
max_perplexity = max(perplexities)
normalized_perps = [p / max_perplexity for p in perplexities]
print(f"Tokens: {tokens}")
print(f"Perplexities: {perplexities}")
print(f"Normalized: {[f'{n:.2f}' for n in normalized_perps]}")
# Test HTML generation
html_parts = ['
']
for i, (token, perp, norm_perp) in enumerate(zip(tokens, perplexities, normalized_perps)):
# Simple color mapping
if norm_perp < 0.3: # Green
red, green, blue = 46, 204, 113
elif norm_perp < 0.7: # Yellow
red, green, blue = 241, 196, 15
else: # Red
red, green, blue = 231, 76, 60
html_parts.append(
f'{token} '
)
html_parts.append('
')
html = ''.join(html_parts)
print(f"\nGenerated HTML:")
print(html)
# Basic checks
assert 'background-color' in html, "No background-color in HTML"
assert 'rgba(' in html, "No rgba colors in HTML"
assert 'title=' in html, "No tooltip in HTML"
print("\nā
Basic HTML generation works!")
print("ā
Colors are included in the HTML!")
print("ā
Tooltips are included!")
return html
def create_test_html_file():
"""Create a test HTML file to visually verify colors"""
html_content = """
Color Test
šØ Perplexity Color Test
Low Perplexity (Green - Confident)
The
quick
brown
Medium Perplexity (Yellow - Uncertain)
machine
learning
requires
High Perplexity (Red - Very Uncertain)
quantum
entanglement
defies
Mixed Example Sentence
The
capital
of
France
is
Paris
Instructions: Hover over tokens to see perplexity values in tooltips!
Color Legend:
- š¢ Green: Low perplexity (model is confident)
- š” Yellow: Medium perplexity (model is somewhat uncertain)
- š“ Red: High perplexity (model is very uncertain)
"""
with open("color_test.html", "w") as f:
f.write(html_content)
print("š¾ Created 'color_test.html' - open this in your browser!")
print(" You should see colored text with different backgrounds")
def main():
"""Run the simple color test"""
try:
print("šØ Simple Color Visualization Test")
print("=" * 60)
# Test HTML generation
html = test_color_html()
# Create visual test file
create_test_html_file()
print("\n" + "=" * 60)
print("š Color test completed successfully!")
print("š Open 'color_test.html' in your browser to see the colors")
print("š” If colors show up there, they should work in the app too!")
print("=" * 60)
return True
except Exception as e:
print(f"ā Test failed: {e}")
return False
if __name__ == "__main__":
success = main()
exit(0 if success else 1)