gujnorm / index.html
sinhal's picture
gujnorm demo (static, runs in the browser)
2f41aa3 verified
Raw History Blame Contribute Delete
6.61 kB
<!doctype html>
<html lang="gu">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>gujnorm</title>
<style>
:root { --bg:#fafaf9; --card:#ffffff; --ink:#1c1917; --muted:#57534e; --line:#e7e5e4; --accent:#4338ca; --accent-ink:#ffffff; --chip:#f5f5f4; }
@media (prefers-color-scheme: dark) { :root { --bg:#141414; --card:#1e1e1e; --ink:#f5f5f4; --muted:#a8a29e; --line:#333; --accent:#818cf8; --accent-ink:#111; --chip:#262626; } }
* { box-sizing:border-box; }
body { margin:0; background:var(--bg); color:var(--ink); font:16px/1.55 system-ui, "Noto Sans Gujarati", sans-serif; }
main { max-width:880px; margin:0 auto; padding:32px 16px 48px; }
h1 { font-size:1.6rem; margin:0 0 4px; }
.sub { color:var(--muted); margin:0 0 20px; }
.card { background:var(--card); border:1px solid var(--line); border-radius:12px; padding:16px; }
label { display:block; font-weight:600; font-size:.9rem; margin:0 0 6px; }
textarea { width:100%; min-height:96px; padding:10px 12px; border:1px solid var(--line); border-radius:8px; background:var(--bg); color:var(--ink); font:1.05rem/1.6 "Noto Sans Gujarati", system-ui, sans-serif; resize:vertical; }
.out { min-height:96px; padding:10px 12px; border:1px solid var(--line); border-radius:8px; background:var(--chip); font-size:1.05rem; white-space:pre-wrap; }
.grid { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
@media (max-width:640px) { .grid { grid-template-columns:1fr; } }
.status { color:var(--muted); font-size:.85rem; margin-top:8px; min-height:1.2em; }
h2 { font-size:1rem; margin:24px 0 8px; }
.chips { display:flex; flex-wrap:wrap; gap:8px; }
.chips button { border:1px solid var(--line); background:var(--chip); color:var(--ink); border-radius:999px; padding:6px 12px; font:inherit; font-size:.9rem; cursor:pointer; }
.chips button:hover { border-color:var(--accent); }
table { width:100%; border-collapse:collapse; font-size:.92rem; }
th, td { text-align:left; padding:8px; border-bottom:1px solid var(--line); vertical-align:top; }
th { color:var(--muted); font-weight:600; }
.wrap { overflow-x:auto; }
a { color:var(--accent); }
footer { color:var(--muted); font-size:.85rem; margin-top:28px; }
code { background:var(--chip); padding:1px 5px; border-radius:4px; }
</style>
</head>
<body>
<main>
<h1>gujnorm</h1>
<p class="sub">Written Gujarati → the words a Gujarati speaker would say, so any TTS voice reads times, ₹ amounts,
fractions, dates, ranges and ordinals correctly. On Sarvam Bulbul it cut misread sentences from 59/55/56 to 0/2/1
(of 108) on three voices.</p>
<div class="card">
<div class="grid">
<div>
<label for="inp">Written Gujarati</label>
<textarea id="inp">તમારો આગલો હપ્તો ₹4,350 તા. 05/12/2026 ના રોજ ભરવાનો છે.</textarea>
</div>
<div>
<label>Spoken form (send this to TTS)</label>
<div class="out" id="out" aria-live="polite"></div>
</div>
</div>
<div class="status" id="status">Loading Python in your browser…</div>
</div>
<h2>Try an example</h2>
<div class="chips" id="chips"></div>
<h2>What TTS does without it</h2>
<div class="wrap"><table>
<tr><th>Written</th><th>Sarvam Bulbul said</th><th>With gujnorm</th></tr>
<tr><td>સવારે 9:30 વાગ્યે</td><td>નવ વાગ્યે ત્રીસ મિનિટ વાગ્યે</td><td>સાડા નવ વાગ્યે</td></tr>
<tr><td>લોન ₹1.5 લાખની</td><td>એક દશાંશ પાંચ લાખ રૂપીઝની</td><td>દોઢ લાખ રૂપિયાની</td></tr>
<tr><td>10-15 દિવસ</td><td>એક શૂન્ય એક પાંચ દિવસ</td><td>દસથી પંદર દિવસ</td></tr>
<tr><td>1લા નંબરે</td><td>એકલા ("alone") નંબરે</td><td>પહેલા નંબરે</td></tr>
<tr><td>8.5%</td><td>આઠ દશાંશ પાંચ પર્સેન્ટ</td><td>સાડા આઠ ટકા</td></tr>
</table></div>
<footer>
Runs entirely in your browser (Pyodide). Nothing you type is sent anywhere.<br>
<a href="https://github.com/Zephyr4772/gujnorm">Code and tests</a> ·
<a href="https://huggingface.co/datasets/sinhal/gujarati-tts-number-reading">Dataset and results</a> ·
<code>pip install git+https://github.com/Zephyr4772/gujnorm</code>
</footer>
</main>
<script src="https://cdn.jsdelivr.net/pyodide/v0.26.4/full/pyodide.js"></script>
<script>
const EXAMPLES = [
"સવારે 9:30 વાગ્યે આવજો.",
"લોન ₹1.5 લાખની છે.",
"તમારું બેલેન્સ ₹99.50 છે.",
"10-15 દિવસ લાગશે.",
"તે 1લા નંબરે આવ્યો.",
"વ્યાજ દર 8.5% છે.",
"બાકી રકમ ₹2,37,450 છે અને વ્યાજ દર 10.75% છે.",
"અમારી શાખા સવારે 9:30 થી સાંજે 4:30 સુધી ખુલ્લી રહે છે.",
"તમારો OTP 482913 છે. મોબાઇલ નંબર 98765 43210.",
"આઝાદી 15 ઓગસ્ટ 1947 એ મળી.",
"દવા 2.5 ml દિવસમાં 3 વાર લેવી.",
];
const inp = document.getElementById("inp"), out = document.getElementById("out"), status = document.getElementById("status");
const chips = document.getElementById("chips");
let normalize = null;
for (const ex of EXAMPLES) {
const b = document.createElement("button");
b.textContent = ex;
b.onclick = () => { inp.value = ex; run(); };
chips.appendChild(b);
}
function run() {
if (!normalize) return;
try { out.textContent = normalize(inp.value); }
catch (e) { out.textContent = ""; status.textContent = "Error: " + e.message; }
}
inp.addEventListener("input", run);
(async () => {
try {
const py = await loadPyodide();
py.FS.mkdir("gujnorm");
for (const f of ["__init__.py", "numbers.py", "rules.py"]) {
const r = await fetch("gujnorm/" + f);
if (!r.ok) throw new Error("could not load gujnorm/" + f);
py.FS.writeFile("gujnorm/" + f, await r.text());
}
const mod = py.pyimport("gujnorm");
normalize = (t) => mod.normalize(t);
status.textContent = "Ready · gujnorm " + mod.__version__ + " · updates as you type";
run();
} catch (e) {
status.textContent = "Could not load: " + e.message;
}
})();
</script>
</body>
</html>