Spaces:
Running
Running
| <html lang="zh-CN"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <title>汉字书法字体识别</title> | |
| <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/> | |
| <meta name="apple-mobile-web-app-capable" content="yes"/> | |
| <style> | |
| /* 基础复位 */ | |
| *{box-sizing:border-box;margin:0;padding:0} | |
| html,body{height:100%;font-family:"Noto Serif SC","Songti SC",serif;background:#f6f2e9;color:#2a2a2a} | |
| body{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:20px} | |
| /* 背景纹理 */ | |
| body::before{ | |
| content:''; | |
| position:fixed;inset:0; | |
| background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAUVBMVEWFhYWDg4N3d3dtbW17e3t1dXWBgYGHh4d5eXlzc3OLi4ubm5uVlZWPj4+NjY19fX2JiYl/f39ra2uRkZGZmZlpaWmXl5dvb29xcXGTk5NnZ2c8TV1mAAAAG3RSTlNAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEAvEOwtAAAFVklEQVR4XpWWB67c2BUFb3g557T/hRo9/WUMZHlgr4Bg8Z4qQgQJlHI4A8SzFVrapvmTF9O7dmYRFZ60YiBhJRCgh1FYhiLAmdvX0CzTOpNE77ME0Zty/nWWzchDtiqrmQDeuv3powQ5ta2eN0FY0InkqDD73lT9c9lEzwUNqgFHs9VQce3TVClFCQrSTfOiYkVJQBmpbq2L6iZavPnAPcoU0dSw0SUTqz/GtrGuXfbyyBniKykOWQWGqwwMA7QiYAxi+IlPdqo+hYHnUt5ZPfnsHJyNiDtnpJyayNBkF6cWoYGAMY92U2hXHF/C1M8uP/ZtYdiuj26UdAdQQSXQErwSOMzt/XWRWAz5GuSBIkwG1H3FabJ2OsUOUhGC6tK4EMtJO0ttC6IBD3kM0ve0tJwMdSfjZo+EEISaeTr9P3wYrGjXqyC1krcKdhMpxEnt5JetoulscpyzhXN5FRpuPHvbeQaKxFAEB6EN+cYN6xD7RYGpXpNndMmZgM5Dcs3YSNFDHUo2LGfZuukSWyUYirJAdYbF3MfqEKmjM+I2EfhA94iG3L7uKrR+GdWD73ydlIB+6hgref1QTlmgmbM3/LeX5GI1Ux1RWpgxpLuZ2+I+IjzZ8wqE4nilvQdkUdfhzI5QDWy+kw5Wgg2pGpeEVeCCA7b85BO3F9DzxB3cdqvBzWcmzbyMiqhzuYqtHRVG2y4x+KOlnyqla8AoWWpuBoYRxzXrfKuILl6SfiWCbjxoZJUaCBj1CjH7GIaDbc9kqBY3W/Rgjda1iqQcOJu2WW+76pZC9QG7M00dffe9hNnseupFL53r8F7YHSwJWUKP2q+k7RdsxyOB11n0xtOvnW4irMMFNV4H0uqwS5ExsmP9AxbDTc9JwgneAT5vTiUSm1E7BSflSt3bfa1tv8Di3R8n3Af7MNWzs49hmauE2wP+ttrq+AsWpFG2awvsuOqbipWHgtuvuaAE+A1Z/7gC9hesnr+7wqCwG8c5yAg3AL1fm8T9AZtp/bbJGwl1pNrE7RuOX7PeMRUERVaPpEs+yqeoSmuOlokqw49pgomjLeh7icHNlG19yjs6XXOMedYm5xH2YxpV2tc0Ro2jJfxC50ApuxGob7lMsxfTbeUv07TyYxpeLucEH1gNd4IKH2LAg5TdVhlCafZvpskfncCfx8pOhJzd76bJWeYFnFciwcYfubRc12Ip/ppIhA1/mSZ/RxjFDrJC5xifFjJpY2Xl5zXdguFqYyTR1zSp1Y9p+tktDYYSNflcxI0iyO4TPBdlRcpeqjK/piF5bklq77V2aGpZU+y4rsaMCCqUEM4NkLFxC4CcxwHu5bXLyGm0x+vd4KuZV0X9fKq2uQJg=='); | |
| opacity:.06;pointer-events:none;z-index:-1; | |
| } | |
| /* 标题卷轴 */ | |
| .title-box{ | |
| background:url('data:image/svg+xml;utf8,\ | |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 60"><rect width="300" height="60" fill="%23d9c7a3" rx="6"/>\ | |
| <path d="M0 50h300" stroke="%239632" stroke-width="2"/></svg>') center/contain no-repeat; | |
| padding:20px 60px;margin-bottom:30px | |
| } | |
| .title-box h1{font-family:"微软雅黑";font-size:32px;letter-spacing:4px;color:#8c1515;font-weight:450} | |
| /* 图片预览 */ | |
| #preview{max-width:100%;max-height:46vh;border:2px solid #8c1515;border-radius:6px;background:#fff} | |
| /* 按钮:朱砂印章效果 */ | |
| .btn{ | |
| margin:24px 0 36px; | |
| padding:12px 48px; | |
| font-size:20px; | |
| letter-spacing:2px; | |
| color:#fff; | |
| background:#8c1515; | |
| border:none; | |
| border-radius:4px; | |
| cursor:pointer; | |
| box-shadow:0 4px 8px rgba(140,21,21,.25); | |
| transition:.2s | |
| } | |
| .btn:active{transform:translateY(2px);box-shadow:0 2px 4px rgba(140,21,21,.25)} | |
| /* 结果卷轴 */ | |
| .result-scroll{ | |
| width:100%; | |
| max-width:420px; | |
| background:#f9f6f0; | |
| border:1px solid #b88868; | |
| border-radius:6px; | |
| box-shadow:0 2px 6px rgba(0,0,0,.15); | |
| display:none; | |
| margin-bottom:30px | |
| } | |
| .result-scroll table{width:100%;border-collapse:collapse} | |
| .result-scroll th,.result-scroll td{padding:12px 8px;text-align:center;font-size:18px} | |
| .result-scroll th{background:#e7d9bd;color:#5c3316;font-weight:600} | |
| .result-scroll tr:nth-child(even){background:#f3ede2} | |
| /* 版权 */ | |
| footer{font-size:14px;color:#7d6446;margin-top:20px;letter-spacing:1px} | |
| </style> | |
| </head> | |
| <body> | |
| <div class="title-box"><h1>汉字书法字体识别</h1></div> | |
| <!-- 图片预览 --> | |
| <img id="preview" alt="点击选择图片" src="han.png" width="200" height="300"/> | |
| <!-- 选择文件 --> | |
| <input id="file" type="file" accept="image/*" hidden/> | |
| <button class="btn" onclick="document.getElementById('file').click()">选择图片</button> | |
| <!-- 识别中提示 --> | |
| <div id="loading" style="display:none;font-size:18px;color:#8c1515;">识别中,请稍候…</div> | |
| <!-- 结果卷轴 --> | |
| <div class="result-scroll" id="result"> | |
| <table> | |
| <thead><tr><th>识别结果</th><th>置信度</th></tr></thead> | |
| <tbody></tbody> | |
| </table> | |
| </div> | |
| <!-- 版权 --> | |
| <footer>>> <a href="https://github.com/jfxia/shufa" target="_blank">github.com/jfxia/shufa</a> <<</footer> | |
| <script> | |
| document.getElementById('file').addEventListener('change', e=>{ | |
| const file = e.target.files[0]; | |
| if(!file) return; | |
| const preview = document.getElementById('preview'); | |
| preview.src = URL.createObjectURL(file); | |
| document.getElementById('result').style.display='none'; | |
| document.getElementById('loading').style.display='block'; | |
| const form = new FormData(); | |
| form.append('file', file); | |
| fetch('/upload', {method:'POST', body:form}) | |
| .then(r=>{if(!r.ok) throw new Error('识别失败 '+r.status); return r.json()}) | |
| .then(list=>{ | |
| const tbody=document.querySelector('#result tbody'); | |
| tbody.innerHTML=''; | |
| list.forEach(item=>{ | |
| const tr=document.createElement('tr'); | |
| tr.innerHTML=`<td>${item.char}</td><td>${item.prob}</td>`; | |
| tbody.appendChild(tr); | |
| }); | |
| document.getElementById('result').style.display='block'; | |
| document.getElementById('loading').style.display='none'; | |
| }) | |
| .catch(err=>{ | |
| alert(err.message||'未知错误'); | |
| document.getElementById('loading').style.display='none'; | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |