Update index.html
Browse files- index.html +38 -8
index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Trích xuất văn bản
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
@@ -23,6 +23,27 @@
|
|
| 23 |
text-align: center;
|
| 24 |
}
|
| 25 |
h2 { color: #333; margin-bottom: 20px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
.upload-area {
|
| 27 |
border: 2px dashed #ccc;
|
| 28 |
padding: 20px;
|
|
@@ -30,6 +51,7 @@
|
|
| 30 |
cursor: pointer;
|
| 31 |
margin-bottom: 20px;
|
| 32 |
transition: 0.3s;
|
|
|
|
| 33 |
}
|
| 34 |
.upload-area:hover { border-color: #007bff; background: #f8fbff; }
|
| 35 |
input[type="file"] { display: none; }
|
|
@@ -60,9 +82,10 @@
|
|
| 60 |
border-radius: 8px;
|
| 61 |
text-align: left;
|
| 62 |
min-height: 80px;
|
| 63 |
-
white-space: pre-wrap;
|
| 64 |
word-wrap: break-word;
|
| 65 |
display: none;
|
|
|
|
| 66 |
}
|
| 67 |
.loading { display: none; margin-top: 15px; color: #666; font-style: italic; }
|
| 68 |
</style>
|
|
@@ -70,7 +93,15 @@
|
|
| 70 |
<body>
|
| 71 |
|
| 72 |
<div class="container">
|
| 73 |
-
<h2>Nhận dạng văn bản (OCR)</h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
<label class="upload-area" for="fileInput">
|
| 76 |
<div id="uploadText">Click để chọn ảnh hoặc Kéo thả ảnh vào đây</div>
|
|
@@ -80,7 +111,7 @@
|
|
| 80 |
|
| 81 |
<button id="submitBtn" disabled>Trích xuất văn bản</button>
|
| 82 |
|
| 83 |
-
<div id="loading" class="loading">Đang
|
| 84 |
<div id="resultBox" class="result-box"></div>
|
| 85 |
</div>
|
| 86 |
|
|
@@ -91,6 +122,7 @@
|
|
| 91 |
const submitBtn = document.getElementById('submitBtn');
|
| 92 |
const resultBox = document.getElementById('resultBox');
|
| 93 |
const loading = document.getElementById('loading');
|
|
|
|
| 94 |
|
| 95 |
let selectedFile = null;
|
| 96 |
|
|
@@ -119,9 +151,9 @@
|
|
| 119 |
|
| 120 |
const formData = new FormData();
|
| 121 |
formData.append('file', selectedFile);
|
|
|
|
| 122 |
|
| 123 |
try {
|
| 124 |
-
// Tự động lấy đúng tên miền của Space hiện tại để gọi API
|
| 125 |
const currentUrl = window.location.href.split('?')[0].replace(/\/$/, "");
|
| 126 |
const apiUrl = currentUrl + "/predict";
|
| 127 |
|
|
@@ -130,7 +162,6 @@
|
|
| 130 |
body: formData
|
| 131 |
});
|
| 132 |
|
| 133 |
-
// Nếu Backend báo lỗi, bóc tách lỗi chi tiết từ Python gửi về
|
| 134 |
if (!response.ok) {
|
| 135 |
const errorData = await response.json();
|
| 136 |
throw new Error(errorData.detail || `Lỗi máy chủ (Mã: ${response.status})`);
|
|
@@ -139,11 +170,10 @@
|
|
| 139 |
const data = await response.json();
|
| 140 |
resultBox.innerText = data.text || "Không tìm thấy chữ trong ảnh.";
|
| 141 |
resultBox.style.display = 'block';
|
| 142 |
-
resultBox.style.color = "#333";
|
| 143 |
|
| 144 |
} catch (error) {
|
| 145 |
console.error(error);
|
| 146 |
-
// In lỗi chính xác ra màn hình
|
| 147 |
resultBox.innerText = "Đã xảy ra lỗi: " + error.message;
|
| 148 |
resultBox.style.display = 'block';
|
| 149 |
resultBox.style.color = "red";
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Trích xuất văn bản Đa Ngôn Ngữ</title>
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
|
|
| 23 |
text-align: center;
|
| 24 |
}
|
| 25 |
h2 { color: #333; margin-bottom: 20px; }
|
| 26 |
+
|
| 27 |
+
/* Style cho phần chọn ngôn ngữ */
|
| 28 |
+
.lang-selector {
|
| 29 |
+
margin-bottom: 20px;
|
| 30 |
+
text-align: left;
|
| 31 |
+
}
|
| 32 |
+
.lang-selector label {
|
| 33 |
+
font-weight: 600;
|
| 34 |
+
color: #555;
|
| 35 |
+
display: block;
|
| 36 |
+
margin-bottom: 8px;
|
| 37 |
+
}
|
| 38 |
+
.lang-selector select {
|
| 39 |
+
width: 100%;
|
| 40 |
+
padding: 10px;
|
| 41 |
+
border-radius: 6px;
|
| 42 |
+
border: 1px solid #ccc;
|
| 43 |
+
font-size: 16px;
|
| 44 |
+
outline: none;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
.upload-area {
|
| 48 |
border: 2px dashed #ccc;
|
| 49 |
padding: 20px;
|
|
|
|
| 51 |
cursor: pointer;
|
| 52 |
margin-bottom: 20px;
|
| 53 |
transition: 0.3s;
|
| 54 |
+
display: block;
|
| 55 |
}
|
| 56 |
.upload-area:hover { border-color: #007bff; background: #f8fbff; }
|
| 57 |
input[type="file"] { display: none; }
|
|
|
|
| 82 |
border-radius: 8px;
|
| 83 |
text-align: left;
|
| 84 |
min-height: 80px;
|
| 85 |
+
white-space: pre-wrap;
|
| 86 |
word-wrap: break-word;
|
| 87 |
display: none;
|
| 88 |
+
border-left: 4px solid #007bff;
|
| 89 |
}
|
| 90 |
.loading { display: none; margin-top: 15px; color: #666; font-style: italic; }
|
| 91 |
</style>
|
|
|
|
| 93 |
<body>
|
| 94 |
|
| 95 |
<div class="container">
|
| 96 |
+
<h2>Nhận dạng văn bản (AI OCR)</h2>
|
| 97 |
+
|
| 98 |
+
<div class="lang-selector">
|
| 99 |
+
<label for="langSelect">Chọn ngôn ngữ trên ảnh:</label>
|
| 100 |
+
<select id="langSelect">
|
| 101 |
+
<option value="vi">🇻🇳 Tiếng Việt (+ Tiếng Anh)</option>
|
| 102 |
+
<option value="zh">🇨🇳 Tiếng Trung Giản Thể (+ Tiếng Anh)</option>
|
| 103 |
+
</select>
|
| 104 |
+
</div>
|
| 105 |
|
| 106 |
<label class="upload-area" for="fileInput">
|
| 107 |
<div id="uploadText">Click để chọn ảnh hoặc Kéo thả ảnh vào đây</div>
|
|
|
|
| 111 |
|
| 112 |
<button id="submitBtn" disabled>Trích xuất văn bản</button>
|
| 113 |
|
| 114 |
+
<div id="loading" class="loading">Đang phân tích ảnh, vui lòng đợi...</div>
|
| 115 |
<div id="resultBox" class="result-box"></div>
|
| 116 |
</div>
|
| 117 |
|
|
|
|
| 122 |
const submitBtn = document.getElementById('submitBtn');
|
| 123 |
const resultBox = document.getElementById('resultBox');
|
| 124 |
const loading = document.getElementById('loading');
|
| 125 |
+
const langSelect = document.getElementById('langSelect'); // Lấy biến ngôn ngữ
|
| 126 |
|
| 127 |
let selectedFile = null;
|
| 128 |
|
|
|
|
| 151 |
|
| 152 |
const formData = new FormData();
|
| 153 |
formData.append('file', selectedFile);
|
| 154 |
+
formData.append('lang', langSelect.value); // Gửi thêm ngôn ngữ xuống Backend
|
| 155 |
|
| 156 |
try {
|
|
|
|
| 157 |
const currentUrl = window.location.href.split('?')[0].replace(/\/$/, "");
|
| 158 |
const apiUrl = currentUrl + "/predict";
|
| 159 |
|
|
|
|
| 162 |
body: formData
|
| 163 |
});
|
| 164 |
|
|
|
|
| 165 |
if (!response.ok) {
|
| 166 |
const errorData = await response.json();
|
| 167 |
throw new Error(errorData.detail || `Lỗi máy chủ (Mã: ${response.status})`);
|
|
|
|
| 170 |
const data = await response.json();
|
| 171 |
resultBox.innerText = data.text || "Không tìm thấy chữ trong ảnh.";
|
| 172 |
resultBox.style.display = 'block';
|
| 173 |
+
resultBox.style.color = "#333";
|
| 174 |
|
| 175 |
} catch (error) {
|
| 176 |
console.error(error);
|
|
|
|
| 177 |
resultBox.innerText = "Đã xảy ra lỗi: " + error.message;
|
| 178 |
resultBox.style.display = 'block';
|
| 179 |
resultBox.style.color = "red";
|