Spaces:
Running
Running
Download web/syntax-test.html from ArielJoe/Prompt-Builder: direct link, hf CLI and curl.
- Browser
- Download file 6.53 kB
-
https://huggingface.co/spaces/ArielJoe/Prompt-Builder/resolve/main/web/syntax-test.html
- Command line
-
hf download hf://spaces/ArielJoe/Prompt-Builder/web/syntax-test.html
-
curl -L -o syntax-test.html https://huggingface.co/spaces/ArielJoe/Prompt-Builder/resolve/main/web/syntax-test.html
6.53 kB
| <html lang="id"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <meta name="description" content="Konsol uji pemeriksaan kewajaran urutan kata dan struktur kalimat Bahasa Indonesia." /> | |
| <title>Syntax Checker: Konsol Uji</title> | |
| <link rel="preconnect" href="https://fonts.googleapis.com" /> | |
| <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> | |
| <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Epilogue:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap" /> | |
| <link rel="stylesheet" href="assets/css/tailwind.css" /> | |
| </head> | |
| <body class="app-shell"> | |
| <header class="topbar"> | |
| <div class="topbar-inner"> | |
| <div class="brand-mark"> | |
| <a href="index.html" class="btn btn--secondary btn-sm">Kembali</a> | |
| <h1 class="brand-title">Deteksi Struktur Kalimat (Syntax)</h1> | |
| </div> | |
| </div> | |
| </header> | |
| <main class="console-container"> | |
| <section class="console-panel"> | |
| <div> | |
| <div class="prompt-field-header"> | |
| <label for="inputText" class="prompt-field-label">Teks uji</label> | |
| <span class="prompt-field-hint">Masukkan satu atau beberapa kalimat Bahasa Indonesia untuk mengecek kewajaran struktur</span> | |
| </div> | |
| <textarea id="inputText" rows="4" class="ink-textarea ink-textarea--resizable" | |
| placeholder="Contoh: Proses pertukaran gas manusia pada terjadi alveolus di."></textarea> | |
| </div> | |
| <div class="flex flex-wrap items-center justify-end gap-2"> | |
| <button id="sampleBtn" type="button" class="btn btn--secondary btn-sm">Contoh Teks</button> | |
| <button id="clearBtn" type="button" class="btn btn--quiet btn-sm">Bersihkan</button> | |
| <button id="checkBtn" type="button" class="btn btn--primary btn-sm">Periksa Struktur</button> | |
| </div> | |
| <div id="errorBox" class="error-banner hidden" role="alert"></div> | |
| </section> | |
| <section class="console-panel"> | |
| <div class="flex flex-wrap items-center justify-between gap-2"> | |
| <h2 class="pane-title">Sorotan Kalimat</h2> | |
| <span id="findingCount" class="prompt-field-hint num">Belum dijalankan</span> | |
| </div> | |
| <div id="highlightBox" class="console-panel--soft text-sm leading-relaxed whitespace-pre-wrap"></div> | |
| <div id="findingsPanel" class="flex flex-col gap-2"></div> | |
| </section> | |
| </main> | |
| <script type="module"> | |
| import { | |
| $, | |
| clearError, | |
| esc, | |
| renderEmptyState, | |
| showError, | |
| } from "./assets/js/test-page-common.js"; | |
| const API = "http://127.0.0.1:8008"; | |
| const SAMPLE = | |
| "Tolong buatkan ringkasan sejarah kemerdekaan Indonesia. " + | |
| "Proses pertukaran gas manusia pada terjadi alveolus di."; | |
| function renderHighlight(text, findings) { | |
| if (!findings.length) { | |
| $("highlightBox").textContent = text; | |
| return; | |
| } | |
| const sorted = [...findings].sort((a, b) => a.start - b.start); | |
| let cursor = 0; | |
| const chunks = []; | |
| for (const f of sorted) { | |
| if (f.start < cursor) continue; | |
| if (f.start > cursor) chunks.push(esc(text.slice(cursor, f.start))); | |
| chunks.push( | |
| `<span class="hl-mark cat-syntax" data-tooltip="${esc(f.reason)}">${esc(text.slice(f.start, f.end))}</span>`, | |
| ); | |
| cursor = f.end; | |
| } | |
| if (cursor < text.length) chunks.push(esc(text.slice(cursor))); | |
| $("highlightBox").innerHTML = chunks.join(""); | |
| } | |
| function renderFindings(text, findings) { | |
| $("findingCount").textContent = `${findings.length} kalimat janggal ditemukan`; | |
| renderHighlight(text, findings); | |
| if (!findings.length) { | |
| $("findingsPanel").innerHTML = renderEmptyState( | |
| "Urutan kalimat terlihat wajar", | |
| "Model tidak mendeteksi struktur kalimat yang janggal pada teks uji.", | |
| ); | |
| return; | |
| } | |
| $("findingsPanel").innerHTML = findings | |
| .map((f) => { | |
| const score = Number.isFinite(Number(f.score)) ? Number(f.score).toFixed(2) : "-"; | |
| return `<div class="finding-row"> | |
| <div class="flex flex-col gap-1"> | |
| <div class="flex flex-wrap items-center gap-2"> | |
| <span class="inline-badge cat-syntax"><span class="entity-dot"></span>Struktur Janggal</span> | |
| <span class="font-mono text-xs font-semibold">“${esc(f.sentence)}”</span> | |
| </div> | |
| <p class="prompt-field-hint">${esc(f.reason || "")}</p> | |
| </div> | |
| <div class="font-mono text-xs text-muted num text-right"> | |
| <div>[${Number(f.start)}:${Number(f.end)}]</div> | |
| <div>skor ${esc(score)}</div> | |
| </div> | |
| </div>`; | |
| }) | |
| .join(""); | |
| } | |
| async function runCheck() { | |
| const text = $("inputText").value; | |
| clearError("errorBox"); | |
| if (!text.trim()) { | |
| showError("errorBox", "Masukkan teks terlebih dahulu sebelum memeriksa struktur kalimat."); | |
| return; | |
| } | |
| const btn = $("checkBtn"); | |
| btn.disabled = true; | |
| btn.textContent = "Memeriksa..."; | |
| try { | |
| const res = await fetch(`${API}/api/syntax`, { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ text }), | |
| }); | |
| if (!res.ok) throw new Error(`HTTP ${res.status}`); | |
| const data = await res.json(); | |
| renderFindings(text, data.findings || []); | |
| } catch (err) { | |
| showError("errorBox", `Gagal menghubungi server Syntax (${API}): ${err.message}`); | |
| } finally { | |
| btn.disabled = false; | |
| btn.textContent = "Periksa Struktur"; | |
| } | |
| } | |
| $("highlightBox").innerHTML = renderEmptyState( | |
| "Belum ada pemeriksaan", | |
| "Isi teks uji atau pilih Contoh Teks lalu klik Periksa Struktur.", | |
| ); | |
| $("sampleBtn").addEventListener("click", () => { | |
| $("inputText").value = SAMPLE; | |
| clearError("errorBox"); | |
| }); | |
| $("clearBtn").addEventListener("click", () => { | |
| $("inputText").value = ""; | |
| clearError("errorBox"); | |
| $("findingCount").textContent = "Belum dijalankan"; | |
| $("highlightBox").innerHTML = renderEmptyState( | |
| "Belum ada pemeriksaan", | |
| "Isi teks uji atau pilih Contoh Teks lalu klik Periksa Struktur.", | |
| ); | |
| $("findingsPanel").innerHTML = ""; | |
| }); | |
| $("checkBtn").addEventListener("click", runCheck); | |
| </script> | |
| </body> | |
| </html> | |