Upload index.html
Browse files12345678910111213141516171819<!doctype html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width" /><title>My static Space</title><link rel="stylesheet" href="style.css" /></head><body><div class="card"><h1>Welcome to your static Space!</h1><p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p><p>Also don't forget to check the<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.</p></div></body></html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566<!DOCTYPE html><html lang="sv"><head><meta charset="UTF-8"><title>Selma Lagerlöf — Predicción de palabra (trigramas)</title><style>body { font-family: sans-serif; max-width: 600px; margin: 40px auto; padding: 0 20px; }input { width: 100%; padding: 10px; font-size: 16px; box-sizing: border-box; }#result { margin-top: 20px; font-size: 18px; min-height: 1.5em; }#status { color: #888; font-size: 14px; }</style></head><body><h1>Selma Lagerlöf — Predicción de la siguiente palabra</h1><p>Modelo de trigramas entrenado sobre el corpus de Selma Lagerlöf(Assignment 2, Language Technology, Lund University).</p><p>Escribe al menos dos palabras en sueco (p. ej. "det var"):</p><input id="textbox" type="text" placeholder="det var" autocomplete="off"><div id="status">Cargando trigramas...</div><div id="result"></div><script>let trigrams = new Map(); // key "w1|w2" -> array of [w3, count]fetch('trigrams.jsonl').then(r => r.text()).then(text => {const lines = text.split('\n').filter(l => l.trim().length > 0);for (const line of lines) {const data = JSON.parse(line);if (data.ngram.length === 3) {const key = data.ngram[0] + '|' + data.ngram[1];if (!trigrams.has(key)) trigrams.set(key, []);trigrams.get(key).push([data.ngram[2], data.count]);}}document.getElementById('status').textContent ='Trigramas cargados: ' + lines.length.toLocaleString();}).catch(err => {document.getElementById('status').textContent ='Error cargando trigrams.jsonl: ' + err;});document.getElementById('textbox').addEventListener('input', function () {const words = this.value.toLowerCase().trim().split(/\s+/);const resultDiv = document.getElementById('result');if (words.length < 2 || words[0] === '') {resultDiv.textContent = '';return;}const w1 = words[words.length - 2];const w2 = words[words.length - 1];const candidates = trigrams.get(w1 + '|' + w2) || [];const sorted = candidates.slice().sort((a, b) => {if (b[1] !== a[1]) return b[1] - a[1]; // frequency descreturn a[0].localeCompare(b[0]); // then alphabetical});const top5 = sorted.slice(0, 5).map(c => c[0]);resultDiv.textContent = top5.length > 0? 'Predicciones: ' + top5.join(', '): 'No hay predicciones para ese contexto.';});</script></body></html>
index.html+65-18