refactor(static): 简化index.html结构并改用iframe加载OCR页面
Browse files将静态页面从完整样式实现改为使用iframe加载外部OCR页面
移除原有样式和脚本逻辑,仅保留基本结构和版权信息
- app.py +5 -5
- static/index.html +21 -226
app.py
CHANGED
|
@@ -281,11 +281,6 @@ async def debug_upload(request: Request, file: UploadFile = File(...)):
|
|
| 281 |
raise HTTPException(status_code=500, detail=str(e))
|
| 282 |
|
| 283 |
|
| 284 |
-
from fastapi.staticfiles import StaticFiles
|
| 285 |
-
|
| 286 |
-
app.mount("/", StaticFiles(directory="static", html=True), name="web")
|
| 287 |
-
|
| 288 |
-
|
| 289 |
@app.get("/")
|
| 290 |
async def root():
|
| 291 |
return {"message": "欢迎使用汉字书法识别模型,请使用 POST /upload 接口上传图片。"}
|
|
@@ -336,6 +331,11 @@ async def upload_text(file: UploadFile = File(...)):
|
|
| 336 |
raise HTTPException(status_code=500, detail=f"服务器内部错误: {e}")
|
| 337 |
|
| 338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
if __name__ == "__main__":
|
| 340 |
import uvicorn
|
| 341 |
|
|
|
|
| 281 |
raise HTTPException(status_code=500, detail=str(e))
|
| 282 |
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
@app.get("/")
|
| 285 |
async def root():
|
| 286 |
return {"message": "欢迎使用汉字书法识别模型,请使用 POST /upload 接口上传图片。"}
|
|
|
|
| 331 |
raise HTTPException(status_code=500, detail=f"服务器内部错误: {e}")
|
| 332 |
|
| 333 |
|
| 334 |
+
from fastapi.staticfiles import StaticFiles
|
| 335 |
+
|
| 336 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="web")
|
| 337 |
+
|
| 338 |
+
|
| 339 |
if __name__ == "__main__":
|
| 340 |
import uvicorn
|
| 341 |
|
static/index.html
CHANGED
|
@@ -1,228 +1,23 @@
|
|
| 1 |
-
<!
|
| 2 |
<html lang="zh-CN">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8" />
|
| 5 |
-
<title>汉字书法字体识别</title>
|
| 6 |
-
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/>
|
| 7 |
-
<meta name="apple-mobile-web-app-capable" content="yes"/>
|
| 8 |
-
<
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
/
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
/
|
| 23 |
-
.title-box{
|
| 24 |
-
background:url('data:image/svg+xml;utf8,\
|
| 25 |
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 60"><rect width="300" height="60" fill="%23d9c7a3" rx="6"/>\
|
| 26 |
-
<path d="M0 50h300" stroke="%239632" stroke-width="2"/></svg>') center/contain no-repeat;
|
| 27 |
-
padding:16px 40px;
|
| 28 |
-
margin:10px 0 20px;
|
| 29 |
-
width: 100%;
|
| 30 |
-
max-width: 320px;
|
| 31 |
-
}
|
| 32 |
-
.title-box h1{
|
| 33 |
-
font-family:"微软雅黑";
|
| 34 |
-
font-size:24px;
|
| 35 |
-
letter-spacing:2px;
|
| 36 |
-
color:#8c1515;
|
| 37 |
-
font-weight:450;
|
| 38 |
-
text-align: center;
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
/* 图片预览 */
|
| 42 |
-
#preview{
|
| 43 |
-
max-width: 100%;
|
| 44 |
-
max-height: 40vh;
|
| 45 |
-
width: auto;
|
| 46 |
-
height: auto;
|
| 47 |
-
border:2px solid #8c1515;
|
| 48 |
-
border-radius:6px;
|
| 49 |
-
background:#fff;
|
| 50 |
-
margin: 10px 0;
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
/* 按钮:朱砂印章效果 */
|
| 54 |
-
.btn{
|
| 55 |
-
margin:20px 0;
|
| 56 |
-
padding:14px 36px;
|
| 57 |
-
font-size:18px;
|
| 58 |
-
letter-spacing:2px;
|
| 59 |
-
color:#fff;
|
| 60 |
-
background:#8c1515;
|
| 61 |
-
border:none;
|
| 62 |
-
border-radius:4px;
|
| 63 |
-
cursor:pointer;
|
| 64 |
-
box-shadow:0 4px 8px rgba(140,21,21,.25);
|
| 65 |
-
transition:.2s;
|
| 66 |
-
min-height: 48px; /* 确保触摸友好 */
|
| 67 |
-
}
|
| 68 |
-
.btn:active{
|
| 69 |
-
transform:translateY(2px);
|
| 70 |
-
box-shadow:0 2px 4px rgba(140,21,21,.25);
|
| 71 |
-
background:#7a1212;
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
/* 识别中提示 */
|
| 75 |
-
#loading{
|
| 76 |
-
display:none;
|
| 77 |
-
font-size:18px;
|
| 78 |
-
color:#8c1515;
|
| 79 |
-
margin: 10px 0;
|
| 80 |
-
text-align: center;
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
/* 结果卷轴 */
|
| 84 |
-
.result-scroll{
|
| 85 |
-
width:100%;
|
| 86 |
-
max-width:420px;
|
| 87 |
-
background:#f9f6f0;
|
| 88 |
-
border:1px solid #b88868;
|
| 89 |
-
border-radius:6px;
|
| 90 |
-
box-shadow:0 2px 6px rgba(0,0,0,.15);
|
| 91 |
-
display:none;
|
| 92 |
-
margin: 10px 0 20px;
|
| 93 |
-
overflow-x: auto; /* 防止表格在小屏幕上溢出 */
|
| 94 |
-
}
|
| 95 |
-
.result-scroll table{
|
| 96 |
-
width:100%;
|
| 97 |
-
border-collapse:collapse;
|
| 98 |
-
min-width: 300px; /* 确保表格在小屏幕上不会过窄 */
|
| 99 |
-
}
|
| 100 |
-
.result-scroll th, .result-scroll td{
|
| 101 |
-
padding:12px 8px;
|
| 102 |
-
text-align:center;
|
| 103 |
-
font-size:16px; /* 稍微减小字体以适应小屏幕 */
|
| 104 |
-
}
|
| 105 |
-
.result-scroll th{
|
| 106 |
-
background:#e7d9bd;
|
| 107 |
-
color:#5c3316;
|
| 108 |
-
font-weight:600;
|
| 109 |
-
}
|
| 110 |
-
.result-scroll tr:nth-child(even){
|
| 111 |
-
background:#f3ede2;
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/* 版权 */
|
| 115 |
-
footer{
|
| 116 |
-
font-size:14px;
|
| 117 |
-
color:#7d6446;
|
| 118 |
-
margin-top:auto; /* 将版权信息推到底部 */
|
| 119 |
-
padding: 10px 0;
|
| 120 |
-
letter-spacing:1px;
|
| 121 |
-
text-align: center;
|
| 122 |
-
}
|
| 123 |
-
footer a {
|
| 124 |
-
color: #7d6446;
|
| 125 |
-
text-decoration: none;
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
/* 移动端特定优化 */
|
| 129 |
-
@media (max-width: 480px) {
|
| 130 |
-
body {
|
| 131 |
-
padding: 12px;
|
| 132 |
-
justify-content: flex-start;
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
.title-box {
|
| 136 |
-
padding: 12px 30px;
|
| 137 |
-
margin: 5px 0 15px;
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
.title-box h1 {
|
| 141 |
-
font-size: 20px;
|
| 142 |
-
letter-spacing: 1px;
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
.btn {
|
| 146 |
-
padding: 12px 28px;
|
| 147 |
-
font-size: 16px;
|
| 148 |
-
margin: 15px 0;
|
| 149 |
-
}
|
| 150 |
-
|
| 151 |
-
.result-scroll th, .result-scroll td {
|
| 152 |
-
padding: 10px 6px;
|
| 153 |
-
font-size: 14px;
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
footer {
|
| 157 |
-
font-size: 12px;
|
| 158 |
-
}
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
/* 防止横屏时元素过大 */
|
| 162 |
-
@media (max-height: 500px) {
|
| 163 |
-
#preview {
|
| 164 |
-
max-height: 30vh;
|
| 165 |
-
}
|
| 166 |
-
}
|
| 167 |
-
</style>
|
| 168 |
-
</head>
|
| 169 |
-
|
| 170 |
-
<body>
|
| 171 |
-
<div class="title-box"><h1>汉字书法字体识别</h1></div>
|
| 172 |
-
|
| 173 |
-
<!-- 图片预览 -->
|
| 174 |
-
<img id="preview" alt="点击选择图片" src="han.png" />
|
| 175 |
-
|
| 176 |
-
<!-- 选择文件 -->
|
| 177 |
-
<input id="file" type="file" accept="image/*" hidden/>
|
| 178 |
-
<button class="btn" onclick="document.getElementById('file').click()">选择图片</button>
|
| 179 |
-
|
| 180 |
-
<!-- 识别中提示 -->
|
| 181 |
-
<div id="loading">识别中,请稍候…</div>
|
| 182 |
-
|
| 183 |
-
<!-- 结果卷轴 -->
|
| 184 |
-
<div class="result-scroll" id="result">
|
| 185 |
-
<table>
|
| 186 |
-
<thead><tr><th>识别结果</th><th>置信度</th></tr></thead>
|
| 187 |
-
<tbody></tbody>
|
| 188 |
-
</table>
|
| 189 |
-
</div>
|
| 190 |
-
|
| 191 |
-
<!-- 版权 -->
|
| 192 |
-
<footer>>> <a href="https://github.com/jfxia/shufa" target="_blank">github.com/jfxia/shufa</a> <<</footer>
|
| 193 |
-
|
| 194 |
-
<script>
|
| 195 |
-
document.getElementById('file').addEventListener('change', e=>{
|
| 196 |
-
const file = e.target.files[0];
|
| 197 |
-
if(!file) return;
|
| 198 |
-
|
| 199 |
-
const preview = document.getElementById('preview');
|
| 200 |
-
preview.src = URL.createObjectURL(file);
|
| 201 |
-
|
| 202 |
-
document.getElementById('result').style.display='none';
|
| 203 |
-
document.getElementById('loading').style.display='block';
|
| 204 |
-
|
| 205 |
-
const form = new FormData();
|
| 206 |
-
form.append('file', file);
|
| 207 |
-
|
| 208 |
-
fetch('/upload', {method:'POST', body:form})
|
| 209 |
-
.then(r=>{if(!r.ok) throw new Error('识别失败 '+r.status); return r.json()})
|
| 210 |
-
.then(list=>{
|
| 211 |
-
const tbody=document.querySelector('#result tbody');
|
| 212 |
-
tbody.innerHTML='';
|
| 213 |
-
list.forEach(item=>{
|
| 214 |
-
const tr=document.createElement('tr');
|
| 215 |
-
tr.innerHTML=`<td>${item.char}</td><td>${item.prob}</td>`;
|
| 216 |
-
tbody.appendChild(tr);
|
| 217 |
-
});
|
| 218 |
-
document.getElementById('result').style.display='block';
|
| 219 |
-
document.getElementById('loading').style.display='none';
|
| 220 |
-
})
|
| 221 |
-
.catch(err=>{
|
| 222 |
-
alert(err.message||'未知错误');
|
| 223 |
-
document.getElementById('loading').style.display='none';
|
| 224 |
-
});
|
| 225 |
-
});
|
| 226 |
-
</script>
|
| 227 |
-
</body>
|
| 228 |
</html>
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
<html lang="zh-CN">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<title>汉字书法字体识别</title>
|
| 6 |
+
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
|
| 7 |
+
<meta name="apple-mobile-web-app-capable" content="yes" />
|
| 8 |
+
</head>
|
| 9 |
+
|
| 10 |
+
<body>
|
| 11 |
+
<!-- iframe容器 -->
|
| 12 |
+
<div class="iframe-container">
|
| 13 |
+
<iframe src="https://www.cyeam.com/mo/ocr"></iframe>
|
| 14 |
+
</div>
|
| 15 |
+
|
| 16 |
+
<!-- 版权 -->
|
| 17 |
+
<footer>
|
| 18 |
+
>>
|
| 19 |
+
<a href="https://github.com/jfxia/shufa" target="_blank">github.com/jfxia/shufa</a>
|
| 20 |
+
<<
|
| 21 |
+
</footer>
|
| 22 |
+
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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