Spaces:
Sleeping
Sleeping
File size: 11,448 Bytes
8c3063a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | <!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EasyOCR - Reconocimiento Rápido</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', sans-serif;
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
min-height: 100vh;
color: #fff;
}
.container { max-width: 900px; margin: 0 auto; padding: 20px; }
.header { text-align: center; padding: 40px 0; }
.header h1 {
font-size: 2.5rem;
background: linear-gradient(90deg, #00ff88, #00d4ff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.header .badge {
background: #00ff88;
color: #000;
padding: 5px 15px;
border-radius: 20px;
font-size: 0.8rem;
font-weight: bold;
margin-top: 10px;
display: inline-block;
}
.status-bar {
display: flex;
justify-content: center;
gap: 20px;
margin-bottom: 30px;
}
.status-item {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 20px;
background: rgba(255,255,255,0.1);
border-radius: 20px;
font-size: 0.85rem;
}
.status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: #ff4444;
}
.status-dot.online {
background: #00ff88;
box-shadow: 0 0 10px #00ff88;
}
.upload-section {
background: rgba(255,255,255,0.05);
border: 2px dashed rgba(255,255,255,0.2);
border-radius: 20px;
padding: 40px;
text-align: center;
cursor: pointer;
transition: all 0.3s;
}
.upload-section:hover {
border-color: #00ff88;
background: rgba(0, 255, 136, 0.05);
}
.upload-icon { font-size: 4rem; margin-bottom: 20px; }
#fileInput { display: none; }
.btn {
background: linear-gradient(90deg, #00ff88, #00d4ff);
border: none;
padding: 15px 40px;
border-radius: 30px;
color: #000;
font-weight: bold;
cursor: pointer;
margin-top: 20px;
transition: transform 0.2s;
}
.btn:hover { transform: translateY(-2px); }
.preview-section { margin-top: 30px; display: none; }
.preview-section.show { display: block; }
.preview-container { display: flex; gap: 20px; flex-wrap: wrap; }
.preview-image, .results-section {
flex: 1;
min-width: 300px;
background: rgba(255,255,255,0.05);
border-radius: 15px;
padding: 20px;
}
.preview-image img { max-width: 100%; border-radius: 10px; }
.preview-image h4 { margin-bottom: 15px; color: #00d4ff; }
.results-section h4 { margin-bottom: 15px; color: #00ff88; }
.result-text {
background: rgba(0,0,0,0.3);
padding: 20px;
border-radius: 10px;
font-size: 1.1rem;
line-height: 1.6;
min-height: 100px;
white-space: pre-wrap;
}
.confidence-bar { margin-top: 20px; }
.confidence-bar label { display: block; margin-bottom: 8px; color: #aaa; }
.progress {
height: 10px;
background: rgba(255,255,255,0.1);
border-radius: 5px;
overflow: hidden;
}
.progress-bar {
height: 100%;
background: linear-gradient(90deg, #00ff88, #00d4ff);
transition: width 0.5s;
}
.confidence-value { text-align: right; margin-top: 5px; color: #00ff88; }
.loading { display: none; text-align: center; padding: 40px; }
.loading.show { display: block; }
.spinner {
width: 50px;
height: 50px;
border: 4px solid rgba(255,255,255,0.1);
border-top-color: #00ff88;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error {
background: rgba(255, 68, 68, 0.2);
border: 1px solid #ff4444;
padding: 20px;
border-radius: 10px;
margin-top: 20px;
display: none;
}
.error.show { display: block; }
.lines-detail { margin-top: 20px; }
.lines-detail h5 { color: #888; margin-bottom: 10px; }
.line-item {
display: flex;
justify-content: space-between;
padding: 8px 12px;
background: rgba(0,0,0,0.2);
border-radius: 8px;
margin-bottom: 6px;
font-size: 0.9rem;
}
.line-conf { color: #00d4ff; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>EasyOCR</h1>
<div class="badge">RÁPIDO ~2-5 seg</div>
<p style="color:#aaa; margin-top:15px;">Reconocimiento de texto - Español e Inglés</p>
</div>
<div class="status-bar">
<div class="status-item">
<div class="status-dot" id="statusDot"></div>
<span id="statusText">Verificando...</span>
</div>
</div>
<div class="upload-section" id="uploadArea">
<div class="upload-icon">📄</div>
<h3>Arrastra tu imagen aquí</h3>
<p style="color:#888;">o haz clic para seleccionar</p>
<input type="file" id="fileInput" accept="image/*">
<button class="btn" id="selectBtn">Seleccionar Imagen</button>
</div>
<div class="loading" id="loading">
<div class="spinner"></div>
<p>Procesando con EasyOCR...</p>
</div>
<div class="error" id="error">
<strong>Error:</strong> <span id="errorText"></span>
</div>
<div class="preview-section" id="previewSection">
<div class="preview-container">
<div class="preview-image">
<h4>📷 Imagen</h4>
<img id="previewImg" src="" alt="Preview">
</div>
<div class="results-section">
<h4>✨ Texto Reconocido</h4>
<div class="result-text" id="resultText">-</div>
<div class="confidence-bar">
<label>Confianza</label>
<div class="progress">
<div class="progress-bar" id="confidenceBar" style="width:0%"></div>
</div>
<div class="confidence-value" id="confidenceValue">0%</div>
</div>
<div class="lines-detail" id="linesDetail">
<h5>Detalle:</h5>
<div id="linesList"></div>
</div>
</div>
</div>
</div>
</div>
<script>
const API_URL = window.location.origin;
const uploadArea = document.getElementById('uploadArea');
const fileInput = document.getElementById('fileInput');
const selectBtn = document.getElementById('selectBtn');
const loading = document.getElementById('loading');
const error = document.getElementById('error');
const errorText = document.getElementById('errorText');
const previewSection = document.getElementById('previewSection');
const previewImg = document.getElementById('previewImg');
const resultText = document.getElementById('resultText');
const confidenceBar = document.getElementById('confidenceBar');
const confidenceValue = document.getElementById('confidenceValue');
const linesList = document.getElementById('linesList');
const statusDot = document.getElementById('statusDot');
const statusText = document.getElementById('statusText');
async function checkStatus() {
try {
const r = await fetch(`${API_URL}/health`);
if (r.ok) {
statusDot.classList.add('online');
statusText.textContent = 'Servidor activo';
}
} catch (e) {
statusDot.classList.remove('online');
statusText.textContent = 'Desconectado';
}
}
checkStatus();
setInterval(checkStatus, 5000);
selectBtn.onclick = (e) => { e.stopPropagation(); fileInput.click(); };
uploadArea.onclick = () => fileInput.click();
uploadArea.ondragover = (e) => { e.preventDefault(); uploadArea.style.borderColor = '#00ff88'; };
uploadArea.ondragleave = () => { uploadArea.style.borderColor = 'rgba(255,255,255,0.2)'; };
uploadArea.ondrop = (e) => {
e.preventDefault();
uploadArea.style.borderColor = 'rgba(255,255,255,0.2)';
if (e.dataTransfer.files[0]) processFile(e.dataTransfer.files[0]);
};
fileInput.onchange = (e) => { if (e.target.files[0]) processFile(e.target.files[0]); };
async function processFile(file) {
const reader = new FileReader();
reader.onload = (e) => { previewImg.src = e.target.result; };
reader.readAsDataURL(file);
loading.classList.add('show');
error.classList.remove('show');
previewSection.classList.remove('show');
try {
const formData = new FormData();
formData.append('file', file);
const response = await fetch(`${API_URL}/recognize`, {
method: 'POST',
body: formData
});
if (!response.ok) throw new Error((await response.json()).detail || 'Error');
const data = await response.json();
loading.classList.remove('show');
previewSection.classList.add('show');
resultText.textContent = data.texto || 'No se detectó texto';
const conf = Math.round(data.confianza * 100);
confidenceBar.style.width = conf + '%';
confidenceValue.textContent = conf + '%';
linesList.innerHTML = '';
if (data.lineas) {
data.lineas.forEach(line => {
const div = document.createElement('div');
div.className = 'line-item';
div.innerHTML = `<span>${line.texto}</span><span class="line-conf">${Math.round(line.confianza*100)}%</span>`;
linesList.appendChild(div);
});
}
} catch (e) {
loading.classList.remove('show');
error.classList.add('show');
errorText.textContent = e.message;
}
}
</script>
</body>
</html>
|