Spaces:
Runtime error
Runtime error
Download interface.html from dborz111/wordsnap-ocr: direct link, hf CLI and curl.
- Browser
- Download file 18.4 kB
-
https://huggingface.co/spaces/dborz111/wordsnap-ocr/resolve/main/interface.html
- Command line
-
hf download hf://spaces/dborz111/wordsnap-ocr/interface.html
-
curl -L -o interface.html https://huggingface.co/spaces/dborz111/wordsnap-ocr/resolve/main/interface.html
18.4 kB
| <html lang="ru"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"> | |
| <meta name="apple-mobile-web-app-capable" content="yes"> | |
| <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> | |
| <title>Помощник для "Слово за слово"</title> | |
| <style> | |
| * { | |
| box-sizing: border-box; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| html, body { | |
| width: 100%; | |
| height: 100%; | |
| margin: 0; | |
| padding: 0; | |
| overflow-x: hidden ; | |
| overflow-y: auto; | |
| -webkit-overflow-scrolling: touch; | |
| background: #000000; | |
| color: #fff; | |
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; | |
| } | |
| body { | |
| padding: 15px; | |
| min-height: 100vh; | |
| } | |
| .container { | |
| max-width: 480px; | |
| margin: 0 auto; | |
| background: linear-gradient(135deg, #0a0a0a, #111); | |
| border-radius: 28px; | |
| padding: 25px; | |
| border: 1px solid rgba(212, 175, 55, 0.25); | |
| box-shadow: 0 20px 60px rgba(0,0,0,0.6); | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| .container::before { | |
| content: ''; | |
| position: absolute; | |
| top: 0; left: 0; right: 0; | |
| height: 4px; | |
| background: linear-gradient(90deg, #d4af37, #f7ef8a, #d4af37); | |
| } | |
| header { | |
| text-align: center; | |
| margin-bottom: 30px; | |
| } | |
| h1 { | |
| font-size: 3.2rem; | |
| font-weight: 900; | |
| background: linear-gradient(135deg, #d4af37, #f7ef8a); | |
| -webkit-background-clip: text; | |
| background-clip: text; | |
| color: transparent; | |
| text-shadow: 0 0 25px rgba(212,175,55,0.4); | |
| margin: 0; | |
| line-height: 1; | |
| } | |
| .subtitle { | |
| font-size: 1.1rem; | |
| color: #d4af37; | |
| margin-top: 8px; | |
| opacity: 0.9; | |
| } | |
| .main-content { | |
| display: grid; | |
| grid-template-columns: 1fr; | |
| gap: 24px; | |
| } | |
| .section { | |
| background: linear-gradient(135deg, #1a1a1a, #111); | |
| border-radius: 22px; | |
| padding: 24px; | |
| border: 1px solid rgba(212,175,55,0.15); | |
| box-shadow: 0 8px 25px rgba(0,0,0,0.4); | |
| } | |
| h2 { | |
| color: #d4af37; | |
| font-size: 1.6rem; | |
| margin-bottom: 20px; | |
| border-bottom: 1px solid rgba(212,175,55,0.2); | |
| padding-bottom: 10px; | |
| } | |
| .file-upload { | |
| border: 3px dashed rgba(212,175,55,0.3); | |
| border-radius: 16px; | |
| padding: 40px 20px; | |
| text-align: center; | |
| cursor: pointer; | |
| transition: all 0.3s; | |
| background: #111; | |
| } | |
| .file-upload:hover, .file-upload.drag-over { | |
| border-color: #d4af37; | |
| background: rgba(212,175,55,0.08); | |
| } | |
| button { | |
| background: linear-gradient(135deg, #d4af37, #c19a2c); | |
| color: #000; | |
| border: none; | |
| padding: 16px 24px; | |
| font-size: 1.1rem; | |
| font-weight: 800; | |
| border-radius: 50px; | |
| cursor: pointer; | |
| width: 100%; | |
| margin-top: 12px; | |
| transition: all 0.3s; | |
| text-transform: uppercase; | |
| letter-spacing: 0.5px; | |
| } | |
| button:hover:not(:disabled) { | |
| transform: translateY(-3px); | |
| box-shadow: 0 12px 30px rgba(212,175,55,0.35); | |
| } | |
| button:disabled { | |
| opacity: 0.5; | |
| cursor: not-allowed; | |
| transform: none; | |
| } | |
| .grid-display { | |
| background: #111; | |
| border: 2px solid rgba(212,175,55,0.25); | |
| border-radius: 16px; | |
| padding: 20px; | |
| min-height: 220px; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| flex-direction: column; | |
| } | |
| .grid-container { | |
| display: inline-block; | |
| background: #1a1a1a; | |
| padding: 12px; | |
| border-radius: 16px; | |
| border: 1px solid rgba(212,175,55,0.2); | |
| } | |
| .grid-row { | |
| display: flex; | |
| } | |
| .grid-cell { | |
| width: 60px; | |
| height: 60px; | |
| margin: 4px; | |
| background: #222; | |
| color: #d4af37; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-size: 2rem; | |
| font-weight: bold; | |
| border-radius: 12px; | |
| cursor: pointer; | |
| transition: all 0.2s; | |
| border: 1px solid rgba(212,175,55,0.1); | |
| } | |
| .grid-cell:hover { | |
| background: #333; | |
| transform: scale(1.08); | |
| } | |
| .words-list { | |
| max-height: 380px; | |
| overflow-y: auto; | |
| background: #111; | |
| border-radius: 16px; | |
| padding: 12px; | |
| } | |
| .word-item { | |
| padding: 14px 18px; | |
| margin: 8px 0; | |
| background: rgba(212,175,55,0.08); | |
| border-radius: 14px; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| color: #fff; | |
| } | |
| .word-text { | |
| font-weight: bold; | |
| color: #d4af37; | |
| font-size: 1.3rem; | |
| } | |
| .word-length { | |
| background: #d4af37; | |
| color: #000; | |
| padding: 6px 12px; | |
| border-radius: 20px; | |
| font-size: 0.9rem; | |
| font-weight: bold; | |
| } | |
| .loading { | |
| text-align: center; | |
| padding: 30px; | |
| } | |
| .spinner { | |
| border: 5px solid rgba(212,175,55,0.2); | |
| border-top: 5px solid #d4af37; | |
| border-radius: 50%; | |
| width: 50px; | |
| height: 50px; | |
| animation: spin 1s linear infinite; | |
| margin: 0 auto 15px; | |
| } | |
| @keyframes spin { to { transform: rotate(360deg); } } | |
| .success, .error { | |
| padding: 16px; | |
| border-radius: 14px; | |
| margin: 16px 0; | |
| text-align: center; | |
| } | |
| .success { background: rgba(212,175,55,0.12); color: #d4af37; border: 1px solid rgba(212,175,55,0.3); } | |
| .error { background: rgba(255,107,107,0.12); color: #ff6b6b; border: 1px solid rgba(255,107,107,0.3); } | |
| .instructions { | |
| background: rgba(212,175,55,0.06); | |
| border-radius: 16px; | |
| padding: 20px; | |
| margin-top: 30px; | |
| border-left: 5px solid #d4af37; | |
| color: #ddd; | |
| } | |
| ::-webkit-scrollbar { | |
| width: 8px; | |
| } | |
| ::-webkit-scrollbar-track { | |
| background: #111; | |
| border-radius: 10px; | |
| } | |
| ::-webkit-scrollbar-thumb { | |
| background: #d4af37; | |
| border-radius: 10px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <header> | |
| <h1>СЛОВО ЗА СЛОВО</h1> | |
| <div class="subtitle">Помощник • находи все слова</div> | |
| </header> | |
| <div class="main-content"> | |
| <!-- Левая часть – загрузка и сетка --> | |
| <div class="section"> | |
| <h2>📸 Загрузи скриншот</h2> | |
| <div class="file-upload" id="dropArea"> | |
| <p style="font-size:1.3rem; margin-bottom:12px;">Перетащи или нажми</p> | |
| <button onclick="document.getElementById('fileInput').click()"> | |
| Выбрать фото | |
| </button> | |
| <input type="file" id="fileInput" accept="image/*" style="display:none;"> | |
| </div> | |
| <img id="previewImage" style="max-width:100%; border-radius:16px; margin-top:16px; display:none;" alt="Превью"> | |
| <button id="analyzeBtn" disabled>🔍 Распознать буквы</button> | |
| <div id="loadingAnalyze" class="loading" style="display:none;"> | |
| <div class="spinner"></div> | |
| <p>Распознаём...</p> | |
| </div> | |
| <div id="gridDisplay" class="grid-display"> | |
| Ожидаю скриншот... | |
| </div> | |
| <button id="findWordsBtn" disabled style="margin-top:20px;">🔎 Найти все слова</button> | |
| </div> | |
| <!-- Правая часть – результаты --> | |
| <div class="section"> | |
| <h2>📝 Найденные слова</h2> | |
| <div id="loadingWords" class="loading" style="display:none;"> | |
| <div class="spinner"></div> | |
| <p>Ищем слова...</p> | |
| </div> | |
| <div id="wordsList" class="words-list"> | |
| <p style="text-align:center; color:#777; padding:60px 0;"> | |
| Слова появятся здесь | |
| </p> | |
| </div> | |
| <div id="successWords" class="success" style="display:none;"></div> | |
| <div id="errorWords" class="error" style="display:none;"></div> | |
| </div> | |
| </div> | |
| <div class="instructions"> | |
| <strong>Как пользоваться:</strong><br> | |
| 1. Сделай скрин всей сетки 5×5<br> | |
| 2. Загрузи фото<br> | |
| 3. Нажми «Распознать буквы»<br> | |
| 4. Нажми на любую букву — откроется клавиатура iPhone<br> | |
| 5. Нажми «Найти все слова» | |
| </div> | |
| </div> | |
| <script> | |
| const API_URL = ''; // если нужно — укажи свой URL, обычно пусто в Spaces | |
| let uploadedFile = null; | |
| let currentGrid = null; | |
| // ==================== Drag & Drop + File Select ==================== | |
| const dropArea = document.getElementById('dropArea'); | |
| ['dragenter', 'dragover'].forEach(e => dropArea.addEventListener(e, highlight, false)); | |
| ['dragleave', 'drop'].forEach(e => dropArea.addEventListener(e, unhighlight, false)); | |
| function highlight() { dropArea.classList.add('drag-over'); } | |
| function unhighlight() { dropArea.classList.remove('drag-over'); } | |
| dropArea.addEventListener('drop', e => { | |
| e.preventDefault(); | |
| handleFiles(e.dataTransfer.files); | |
| }); | |
| document.getElementById('fileInput').addEventListener('change', e => { | |
| handleFiles(e.target.files); | |
| }); | |
| function handleFiles(files) { | |
| if (!files.length) return; | |
| uploadedFile = files[0]; | |
| const preview = document.getElementById('previewImage'); | |
| preview.src = URL.createObjectURL(uploadedFile); | |
| preview.style.display = 'block'; | |
| document.getElementById('analyzeBtn').disabled = false; | |
| resetResults(); | |
| } | |
| function resetResults() { | |
| currentGrid = null; | |
| document.getElementById('gridDisplay').innerHTML = 'Ожидаю скриншот...'; | |
| document.getElementById('findWordsBtn').disabled = true; | |
| document.getElementById('wordsList').innerHTML = '<p style="text-align:center; color:#777; padding:60px 0;">Слова появятся здесь</p>'; | |
| } | |
| // ==================== Анализ изображения ==================== | |
| document.getElementById('analyzeBtn').onclick = async () => { | |
| if (!uploadedFile) return alert('Сначала выбери фото'); | |
| document.getElementById('loadingAnalyze').style.display = 'block'; | |
| document.getElementById('analyzeBtn').disabled = true; | |
| const formData = new FormData(); | |
| formData.append('file', uploadedFile); | |
| try { | |
| const res = await fetch('/vision', { method: 'POST', body: formData }); | |
| const data = await res.json(); | |
| if (data.error) throw new Error(data.error); | |
| currentGrid = data.grid; | |
| displayGrid(currentGrid); | |
| document.getElementById('findWordsBtn').disabled = false; | |
| } catch (e) { | |
| alert('Ошибка: ' + e.message); | |
| } finally { | |
| document.getElementById('loadingAnalyze').style.display = 'none'; | |
| document.getElementById('analyzeBtn').disabled = false; | |
| } | |
| }; | |
| // ==================== Отображение сетки с редактируемыми ячейками ==================== | |
| function displayGrid(grid) { | |
| const container = document.getElementById('gridDisplay'); | |
| container.innerHTML = ''; | |
| const gridDiv = document.createElement('div'); | |
| gridDiv.className = 'grid-container'; | |
| grid.forEach((row, rowIndex) => { | |
| const rowDiv = document.createElement('div'); | |
| rowDiv.className = 'grid-row'; | |
| row.forEach((letter, colIndex) => { | |
| const cell = document.createElement('div'); | |
| cell.className = 'grid-cell'; | |
| cell.textContent = letter || '?'; | |
| cell.dataset.row = rowIndex; | |
| cell.dataset.col = colIndex; | |
| cell.onclick = () => makeEditable(cell); | |
| rowDiv.appendChild(cell); | |
| }); | |
| gridDiv.appendChild(rowDiv); | |
| }); | |
| container.appendChild(gridDiv); | |
| } | |
| function makeEditable(cell) { | |
| if (cell.querySelector('input')) return; | |
| const row = cell.dataset.row; | |
| const col = cell.dataset.col; | |
| const oldLetter = cell.textContent.trim(); | |
| const input = document.createElement('input'); | |
| input.type = 'text'; | |
| input.maxLength = 1; | |
| input.value = oldLetter === '?' ? '' : oldLetter; | |
| input.style.cssText = ` | |
| width:100%; height:100%; | |
| font-size:2rem; text-align:center; | |
| background:transparent; color:#d4af37; | |
| border:none; outline:none; | |
| `; | |
| input.autocapitalize = 'characters'; | |
| input.inputMode = 'text'; | |
| cell.innerHTML = ''; | |
| cell.appendChild(input); | |
| input.focus(); | |
| const save = async () => { | |
| let val = input.value.trim().toUpperCase(); | |
| if (val.length > 1) val = val[0]; | |
| if (!val) val = '?'; | |
| try { | |
| const res = await fetch('/correct_letter', { | |
| method: 'POST', | |
| headers: {'Content-Type': 'application/json'}, | |
| body: JSON.stringify({row: +row, col: +col, letter: val, grid: currentGrid}) | |
| }); | |
| const data = await res.json(); | |
| if (data.success) { | |
| currentGrid = data.corrected_grid; | |
| cell.textContent = val; | |
| } else { | |
| cell.textContent = currentGrid[row][col]; | |
| } | |
| } catch { | |
| cell.textContent = currentGrid[row][col]; | |
| } | |
| }; | |
| input.onblur = save; | |
| input.onkeydown = e => { | |
| if (e.key === 'Enter') { | |
| e.preventDefault(); | |
| input.blur(); | |
| } | |
| }; | |
| } | |
| // ==================== Поиск слов ==================== | |
| document.getElementById('findWordsBtn').onclick = async () => { | |
| if (!currentGrid) return alert('Сначала распознай буквы'); | |
| document.getElementById('loadingWords').style.display = 'block'; | |
| document.getElementById('findWordsBtn').disabled = true; | |
| try { | |
| const res = await fetch('/solve', { | |
| method: 'POST', | |
| headers: {'Content-Type': 'application/json'}, | |
| body: JSON.stringify(currentGrid) | |
| }); | |
| const data = await res.json(); | |
| if (data.error) throw new Error(data.error); | |
| displayWords(data.best_words || []); | |
| } catch (e) { | |
| alert('Ошибка поиска: ' + e.message); | |
| } finally { | |
| document.getElementById('loadingWords').style.display = 'none'; | |
| document.getElementById('findWordsBtn').disabled = false; | |
| } | |
| }; | |
| function displayWords(words) { | |
| const list = document.getElementById('wordsList'); | |
| list.innerHTML = ''; | |
| if (!words.length) { | |
| list.innerHTML = '<p style="text-align:center; color:#777; padding:60px 0;">Слова не найдены</p>'; | |
| return; | |
| } | |
| words.sort((a,b) => b.length - a.length); | |
| words.forEach((item, i) => { | |
| const div = document.createElement('div'); | |
| div.className = 'word-item'; | |
| div.innerHTML = ` | |
| <span class="word-text">${item.word}</span> | |
| <span class="word-length">${item.length} букв</span> | |
| `; | |
| div.onclick = () => navigator.clipboard.writeText(item.word) | |
| .then(() => alert('Скопировано: ' + item.word)); | |
| list.appendChild(div); | |
| }); | |
| } | |
| </script> | |
| </body> | |
| </html> |