Spaces:
Running
Running
Commit
·
04ab453
1
Parent(s):
5485eca
Fix Chinese character encoding in tooltip display
Browse filesFixed UTF-8 decoding issue where Chinese characters were displayed as
garbled text (e.g., 预计 instead of 预计) in the top-10 predictions
tooltip.
Root cause: JavaScript's atob() function only supports Latin-1 encoding,
not UTF-8. When decoding base64-encoded JSON containing Chinese characters,
each UTF-8 byte was incorrectly interpreted as a separate Latin-1 character.
Solution: Implemented proper UTF-8 decoding by:
1. Using atob() to decode base64 to binary string
2. Converting binary string to Uint8Array
3. Using TextDecoder('utf-8') to correctly decode UTF-8 bytes
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
visualization/html_generator.py
CHANGED
|
@@ -773,8 +773,13 @@ def generate_comparison_html(
|
|
| 773 |
function formatTopkColumn(topkBase64, modelName, titleClass) {{
|
| 774 |
if (!topkBase64) return '<div class="topk-column"><div class="topk-title ' + titleClass + '">' + modelName + '</div><div class="topk-list">N/A</div></div>';
|
| 775 |
try {{
|
| 776 |
-
// Decode base64 to
|
| 777 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 778 |
const data = JSON.parse(topkJson);
|
| 779 |
const [actualId, rank, topkList] = data;
|
| 780 |
let html = '<div class="topk-column">';
|
|
|
|
| 773 |
function formatTopkColumn(topkBase64, modelName, titleClass) {{
|
| 774 |
if (!topkBase64) return '<div class="topk-column"><div class="topk-title ' + titleClass + '">' + modelName + '</div><div class="topk-list">N/A</div></div>';
|
| 775 |
try {{
|
| 776 |
+
// Decode base64 to UTF-8 string (atob() doesn't support UTF-8, need proper decoding)
|
| 777 |
+
const binaryString = atob(topkBase64);
|
| 778 |
+
const bytes = new Uint8Array(binaryString.length);
|
| 779 |
+
for (let i = 0; i < binaryString.length; i++) {{
|
| 780 |
+
bytes[i] = binaryString.charCodeAt(i);
|
| 781 |
+
}}
|
| 782 |
+
const topkJson = new TextDecoder('utf-8').decode(bytes);
|
| 783 |
const data = JSON.parse(topkJson);
|
| 784 |
const [actualId, rank, topkList] = data;
|
| 785 |
let html = '<div class="topk-column">';
|