Spaces:
Paused
Paused
File size: 27,159 Bytes
3e08449 | 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 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | /**
* ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
* LinguaVerify AI v5.1 - COMPLETE PRODUCTION JAVASCRIPT
* Frontend Logic β’ Text Visibility FIXED β’ All Features Working
* Author: Your Name | Date: Oct 2025 | Version: 5.1
* ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
*/
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GLOBAL STATE
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
let currentResult = null;
// Language names mapping
const LANGUAGE_NAMES = {
'en': 'English', 'es': 'Spanish', 'fr': 'French', 'de': 'German',
'hi': 'Hindi', 'ar': 'Arabic', 'zh': 'Chinese', 'ja': 'Japanese',
'ko': 'Korean', 'ru': 'Russian', 'pt': 'Portuguese', 'it': 'Italian',
'nl': 'Dutch', 'tr': 'Turkish', 'pl': 'Polish', 'th': 'Thai',
'vi': 'Vietnamese', 'id': 'Indonesian', 'ta': 'Tamil', 'te': 'Telugu',
'bn': 'Bengali', 'ur': 'Urdu', 'fa': 'Persian', 'he': 'Hebrew',
'mr': 'Marathi', 'gu': 'Gujarati', 'kn': 'Kannada', 'ml': 'Malayalam',
'pa': 'Punjabi', 'si': 'Sinhala', 'ne': 'Nepali', 'my': 'Burmese',
'km': 'Khmer', 'lo': 'Lao', 'am': 'Amharic', 'sw': 'Swahili',
'unknown': 'Unknown'
};
// Example datasets
const examples = {
1: {
title_a: "Deep Learning for Medical Diagnosis",
title_b: "ΰ€ΰ€Ώΰ€ΰ€Ώΰ€€ΰ₯ΰ€Έΰ€Ύ ΰ€¨ΰ€Ώΰ€¦ΰ€Ύΰ€¨ ΰ€ΰ₯ ΰ€²ΰ€Ώΰ€ ΰ€‘ΰ₯ΰ€ͺ ΰ€²ΰ€°ΰ₯ΰ€¨ΰ€Ώΰ€ΰ€",
domain: "medicine"
},
2: {
title_a: "Climate Change Impact on Agriculture",
title_b: "Impacto del Cambio ClimΓ‘tico en la Agricultura",
domain: "climate_change"
},
3: {
title_a: "Artificial Intelligence Research and Development",
title_b: "Ψ¨ΨΨ« ΩΨͺΨ·ΩΩΨ± Ψ§ΩΨ°ΩΨ§Ψ‘ Ψ§ΩΨ§Ψ΅Ψ·ΩΨ§ΨΉΩ",
domain: "artificial_intelligence"
}
};
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// INITIALIZATION
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
document.addEventListener('DOMContentLoaded', () => {
console.log('%cπ§ LinguaVerify AI v5.1 - PRODUCTION READY',
'color: #a78bfa; font-size: 16px; font-weight: bold; background: #1a1f3a; padding: 10px; border-radius: 5px;');
console.log('%c⨠All Features Active', 'color: #10b981; font-size: 12px;');
initializeApp();
setupEventListeners();
checkSystemHealth();
fixInputVisibility();
console.log('%cβ¨οΈ Keyboard Shortcuts:', 'color: #a78bfa; font-weight: bold;');
console.log(' Ctrl/Cmd + Enter: Verify titles');
console.log(' Esc: Clear results');
});
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// TEXT VISIBILITY FIX (CRITICAL)
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function fixInputVisibility() {
const inputs = document.querySelectorAll('.luxury-input, .luxury-select');
inputs.forEach(input => {
// Set text color
input.style.color = '#ffffff';
input.style.webkitTextFillColor = '#ffffff';
// Fix on input event
input.addEventListener('input', function() {
this.style.color = '#ffffff';
this.style.webkitTextFillColor = '#ffffff';
});
// Fix on focus
input.addEventListener('focus', function() {
this.style.color = '#ffffff';
this.style.webkitTextFillColor = '#ffffff';
});
// Fix on blur
input.addEventListener('blur', function() {
this.style.color = '#ffffff';
this.style.webkitTextFillColor = '#ffffff';
});
});
console.log('β
Input visibility enforced');
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// APP INITIALIZATION
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function initializeApp() {
const titleA = document.getElementById('title_a');
const titleB = document.getElementById('title_b');
if (titleA) {
updateCharCount('title_a', 'char_count_a');
detectLanguageRealtime('title_a', 'detected_lang_a', 'lang_badge_a');
titleA.addEventListener('input', () => {
updateCharCount('title_a', 'char_count_a');
detectLanguageRealtime('title_a', 'detected_lang_a', 'lang_badge_a');
});
}
if (titleB) {
updateCharCount('title_b', 'char_count_b');
detectLanguageRealtime('title_b', 'detected_lang_b', 'lang_badge_b');
titleB.addEventListener('input', () => {
updateCharCount('title_b', 'char_count_b');
detectLanguageRealtime('title_b', 'detected_lang_b', 'lang_badge_b');
});
}
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// EVENT LISTENERS
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function setupEventListeners() {
// Keyboard shortcuts
document.addEventListener('keydown', (e) => {
// Ctrl/Cmd + Enter to verify
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault();
verifyTitles();
}
// Escape to clear results
if (e.key === 'Escape') {
const results = document.getElementById('results');
if (results && results.style.display !== 'none') {
hideResults();
showNotification('Results cleared', 'info');
}
}
});
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// CHARACTER COUNTING
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function updateCharCount(textareaId, countId) {
const textarea = document.getElementById(textareaId);
const counter = document.getElementById(countId);
if (textarea && counter) {
const length = textarea.value.length;
counter.textContent = `${length} char${length !== 1 ? 's' : ''}`;
// Change color if too long
if (length > 500) {
counter.style.color = '#f59e0b';
} else {
counter.style.color = 'rgba(255, 255, 255, 0.4)';
}
}
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// REAL-TIME LANGUAGE DETECTION
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
let languageDetectionTimeouts = {};
function detectLanguageRealtime(textareaId, langSpanId, badgeId) {
const textarea = document.getElementById(textareaId);
const langSpan = document.getElementById(langSpanId);
const badge = document.getElementById(badgeId);
if (!textarea || !langSpan || !badge) return;
const text = textarea.value.trim();
// Handle empty input
if (!text) {
langSpan.textContent = 'Waiting...';
badge.style.background = 'rgba(139, 92, 246, 0.15)';
badge.style.borderColor = 'rgba(139, 92, 246, 0.25)';
badge.style.color = '#a78bfa';
return;
}
// Show detecting state
langSpan.textContent = 'Detecting...';
badge.style.background = 'rgba(59, 130, 246, 0.15)';
badge.style.borderColor = 'rgba(59, 130, 246, 0.25)';
badge.style.color = '#60a5fa';
// Clear previous timeout
if (languageDetectionTimeouts[textareaId]) {
clearTimeout(languageDetectionTimeouts[textareaId]);
}
// Debounce API call
languageDetectionTimeouts[textareaId] = setTimeout(() => {
fetch('/detect_language', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: text })
})
.then(response => response.json())
.then(data => {
const langName = LANGUAGE_NAMES[data.language] || data.language.toUpperCase();
const confidence = Math.round(data.confidence * 100);
langSpan.textContent = `${langName} (${confidence}%)`;
badge.style.background = 'rgba(16, 185, 129, 0.15)';
badge.style.borderColor = 'rgba(16, 185, 129, 0.25)';
badge.style.color = '#34d399';
})
.catch(error => {
console.error('Language detection error:', error);
langSpan.textContent = 'Auto-detect';
badge.style.background = 'rgba(239, 68, 68, 0.15)';
badge.style.borderColor = 'rgba(239, 68, 68, 0.25)';
badge.style.color = '#f87171';
});
}, 500); // 500ms debounce
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// EXAMPLE LOADING
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function loadExample(id) {
const example = examples[id];
if (!example) {
showNotification('Example not found', 'error');
return;
}
const titleA = document.getElementById('title_a');
const titleB = document.getElementById('title_b');
const domain = document.getElementById('domain');
if (titleA && titleB && domain) {
// Set values
titleA.value = example.title_a;
titleB.value = example.title_b;
domain.value = example.domain;
// Force text visibility
titleA.style.color = '#ffffff';
titleB.style.color = '#ffffff';
titleA.style.webkitTextFillColor = '#ffffff';
titleB.style.webkitTextFillColor = '#ffffff';
// Update UI
updateCharCount('title_a', 'char_count_a');
updateCharCount('title_b', 'char_count_b');
detectLanguageRealtime('title_a', 'detected_lang_a', 'lang_badge_a');
detectLanguageRealtime('title_b', 'detected_lang_b', 'lang_badge_b');
// Auto-verify after 1 second
setTimeout(() => verifyTitles(), 1000);
showNotification('β
Example loaded successfully', 'success');
}
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// MAIN VERIFICATION FUNCTION
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
async function verifyTitles() {
const titleA = document.getElementById('title_a')?.value.trim();
const titleB = document.getElementById('title_b')?.value.trim();
const domain = document.getElementById('domain')?.value;
const enableTranslation = document.getElementById('enable_translation')?.checked;
// Validation
if (!titleA || !titleB) {
showNotification('β οΈ Please enter both titles', 'warning');
return;
}
// Set loading state
setLoadingState(true);
hideResults();
try {
const response = await fetch('/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title_a: titleA,
title_b: titleB,
domain: domain,
enable_translation: enableTranslation
})
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || `HTTP ${response.status}`);
}
const result = await response.json();
currentResult = result;
// Display results with animation delay
setTimeout(() => {
displayResults(result, domain, enableTranslation);
}, 300);
showNotification('β
Analysis complete', 'success');
} catch (error) {
console.error('Verification error:', error);
showNotification('β Error: ' + error.message, 'error');
} finally {
setLoadingState(false);
}
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// LOADING STATE MANAGEMENT
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function setLoadingState(isLoading) {
const btnContent = document.getElementById('btn-content');
const btnLoader = document.getElementById('btn-loader');
const button = document.querySelector('.btn-primary-gradient');
if (btnContent && btnLoader && button) {
if (isLoading) {
btnContent.style.display = 'none';
btnLoader.style.display = 'flex';
button.disabled = true;
button.style.opacity = '0.7';
button.style.cursor = 'not-allowed';
} else {
btnContent.style.display = 'flex';
btnLoader.style.display = 'none';
button.disabled = false;
button.style.opacity = '1';
button.style.cursor = 'pointer';
}
}
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// DISPLAY RESULTS
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function displayResults(result, domain, translationEnabled) {
const resultsPanel = document.getElementById('results');
if (!resultsPanel) return;
// Show results panel
resultsPanel.style.display = 'block';
// Smooth scroll to results
setTimeout(() => {
resultsPanel.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}, 100);
// Update decision badge
const badge = document.getElementById('decision-badge');
if (badge) {
badge.textContent = result.label.replace('_', ' ');
badge.className = 'decision-badge-luxury ' +
(result.label === 'EQUIVALENT' ? 'equivalent' : 'not-equivalent');
}
// Update translation panel
const translationPanel = document.getElementById('translation-panel');
if (translationEnabled && result.translations && translationPanel) {
translationPanel.style.display = 'block';
// Translation A
const transA = result.translations.title_a;
if (transA) {
document.getElementById('trans_lang_a').textContent =
(transA.src_lang || 'auto').toUpperCase();
document.getElementById('trans_original_a').textContent = transA.original_text;
document.getElementById('trans_result_a').textContent = transA.translated_text;
}
// Translation B
const transB = result.translations.title_b;
if (transB) {
document.getElementById('trans_lang_b').textContent =
(transB.src_lang || 'auto').toUpperCase();
document.getElementById('trans_original_b').textContent = transB.original_text;
document.getElementById('trans_result_b').textContent = transB.translated_text;
}
} else if (translationPanel) {
translationPanel.style.display = 'none';
}
// Animate metrics
animateMetric('final-score', result.final_score, 3);
animateMetric('embedding-score', result.embedding_score, 3);
animateProgressBar('progress-final', result.final_score * 100);
animateProgressBar('progress-embed', result.embedding_score * 100);
// Translation score (if available)
const translationScoreCard = document.getElementById('translation-score-card');
const translationScoreValue = document.getElementById('translation-score');
if (result.translation_score !== null && translationScoreCard && translationScoreValue) {
translationScoreCard.style.display = 'block';
animateMetric('translation-score', result.translation_score, 3);
animateProgressBar('progress-trans', result.translation_score * 100);
} else if (translationScoreCard) {
translationScoreCard.style.display = 'none';
}
// Update other metrics
document.getElementById('confidence').textContent = result.confidence;
document.getElementById('processing-time').textContent = result.traces.total_time_ms + 'ms';
document.getElementById('method').textContent =
(result.method || 'labse_only').replace(/_/g, ' ').toUpperCase();
// Language detection
const langs = result.detected_languages;
document.getElementById('lang_detect_a').textContent =
LANGUAGE_NAMES[langs.title_a] || langs.title_a.toUpperCase();
document.getElementById('lang_detect_b').textContent =
LANGUAGE_NAMES[langs.title_b] || langs.title_b.toUpperCase();
document.getElementById('lang_conf_a').textContent =
Math.round(langs.confidence_a * 100) + '%';
document.getElementById('lang_conf_b').textContent =
Math.round(langs.confidence_b * 100) + '%';
// Metadata
const domainFormatted = domain.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
document.getElementById('domain-display').textContent = domainFormatted;
document.getElementById('threshold').textContent = result.adjusted_threshold.toFixed(3);
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// ANIMATED COUNTERS
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function animateMetric(elementId, targetValue, decimals = 0) {
const element = document.getElementById(elementId);
if (!element) return;
const duration = 1000; // 1 second
const startValue = 0;
const increment = (targetValue - startValue) / (duration / 16);
let currentValue = startValue;
const counter = setInterval(() => {
currentValue += increment;
if (currentValue >= targetValue) {
currentValue = targetValue;
clearInterval(counter);
}
element.textContent = currentValue.toFixed(decimals);
}, 16); // ~60fps
}
function animateProgressBar(elementId, targetWidth) {
const element = document.getElementById(elementId);
if (!element) return;
// Start from 0
element.style.width = '0%';
// Animate to target
setTimeout(() => {
element.style.width = Math.min(targetWidth, 100) + '%';
}, 100);
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// UTILITY FUNCTIONS
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function hideResults() {
const resultsPanel = document.getElementById('results');
if (resultsPanel) {
resultsPanel.style.display = 'none';
}
}
function showNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.textContent = message;
// Styling
Object.assign(notification.style, {
position: 'fixed',
top: '100px',
right: '20px',
padding: '1rem 1.5rem',
borderRadius: '12px',
color: 'white',
fontSize: '0.9rem',
fontWeight: '500',
zIndex: '10000',
opacity: '0',
transform: 'translateX(400px)',
transition: 'all 0.3s cubic-bezier(0.4, 0, 0.2, 1)',
boxShadow: '0 8px 32px rgba(0, 0, 0, 0.3)',
backdropFilter: 'blur(10px)'
});
// Type-specific colors
if (type === 'success') {
notification.style.background = 'linear-gradient(135deg, rgba(16, 185, 129, 0.9), rgba(5, 150, 105, 0.9))';
} else if (type === 'error') {
notification.style.background = 'linear-gradient(135deg, rgba(239, 68, 68, 0.9), rgba(220, 38, 38, 0.9))';
} else if (type === 'warning') {
notification.style.background = 'linear-gradient(135deg, rgba(245, 158, 11, 0.9), rgba(217, 119, 6, 0.9))';
} else {
notification.style.background = 'linear-gradient(135deg, rgba(59, 130, 246, 0.9), rgba(37, 99, 235, 0.9))';
}
document.body.appendChild(notification);
// Slide in
setTimeout(() => {
notification.style.opacity = '1';
notification.style.transform = 'translateX(0)';
}, 10);
// Slide out and remove
setTimeout(() => {
notification.style.opacity = '0';
notification.style.transform = 'translateX(400px)';
setTimeout(() => notification.remove(), 300);
}, 3000);
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// SYSTEM HEALTH CHECK
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
async function checkSystemHealth() {
try {
const response = await fetch('/health');
const data = await response.json();
console.log('%cπ’ System Health:', 'color: #10b981; font-weight: bold;');
console.log(' Status:', data.status);
console.log(' Version:', data.version);
console.log(' Models:', data.models);
console.log(' Cache:', data.cache_size);
console.log(' Device:', data.device);
} catch (error) {
console.warn('%cβ οΈ Could not fetch health status:', 'color: #f59e0b;', error);
}
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GLOBAL EXPORTS
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
window.verifyTitles = verifyTitles;
window.loadExample = loadExample;
window.hideResults = hideResults;
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// CONSOLE BRANDING
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
console.log('%cββββββββββββββββββββββββββββββββββββββββββββββββββ', 'color: #a78bfa;');
console.log('%cπ§ LinguaVerify AI v5.1 - Production Ready', 'color: #10b981; font-size: 14px; font-weight: bold;');
console.log('%c200+ Languages β’ Dual-Path AI β’ Text Visibility Fixed β
', 'color: #10b981; font-size: 11px;');
console.log('%cββββββββββββββββββββββββββββββββββββββββββββββββββ', 'color: #a78bfa;');
console.log('%cDeveloped with β€οΈ by Your Name', 'color: #60a5fa; font-size: 10px;');
console.log('%cββββββββββββββββββββββββββββββββββββββββββββββββββ', 'color: #a78bfa;');
|