Spaces:
Running
Running
| <html lang="ja"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>LLM Token</title> | |
| <style> | |
| body { font-family: sans-serif; max-width: 800px; margin: 40px auto; padding: 0 20px; line-height: 1.6; background-color: #f9f9f9; } | |
| textarea { width: 100%; height: 250px; padding: 15px; border: 2px solid #ddd; border-radius: 10px; font-size: 16px; box-sizing: border-box; } | |
| textarea:focus { border-color: #007bff; outline: none; } | |
| .stats { display: flex; gap: 30px; margin-top: 15px; background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); } | |
| .stat-item { display: flex; flex-direction: column; } | |
| .label { font-size: 0.9em; color: #666; } | |
| .value { font-size: 1.5em; font-weight: bold; color: #007bff; } | |
| </style> | |
| </head> | |
| <body> | |
| <h2>LLM トークンカウンター</h2> | |
| <textarea id="inputText" placeholder="ここに文章を入力してください..."></textarea> | |
| <div class="stats"> | |
| <div class="stat-item"> | |
| <span class="label">トークン数</span> | |
| <span id="tokenCount" class="value">0</span> | |
| </div> | |
| <div class="stat-item"> | |
| <span class="label">文字数</span> | |
| <span id="charCount" class="value">0</span> | |
| </div> | |
| </div> | |
| <script type="module"> | |
| import { getEncoding } from "https://cdn.jsdelivr.net/npm/js-tiktoken@1.0.7/+esm"; | |
| const input = document.getElementById('inputText'); | |
| const tokenDisplay = document.getElementById('tokenCount'); | |
| const charDisplay = document.getElementById('charCount'); | |
| // エンコーダーの初期化 | |
| const enc = getEncoding("cl100k_base"); | |
| input.addEventListener('input', () => { | |
| const text = input.value; | |
| if (text) { | |
| // トークン化して長さを計算 | |
| const tokens = enc.encode(text); | |
| tokenDisplay.textContent = tokens.length.toLocaleString(); | |
| } else { | |
| tokenDisplay.textContent = "0"; | |
| } | |
| charDisplay.textContent = text.length.toLocaleString(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |