Spaces:
Running
Running
File size: 7,128 Bytes
3785cde ccb3666 3785cde ea78f87 3785cde ea78f87 3785cde ea78f87 3785cde ea78f87 3785cde ea78f87 3785cde |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BanglaFeel Translator</title>
<link rel="stylesheet" href="/static/style.css" />
<link href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500&family=Roboto:wght@400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<div class="page-container">
<header>
<h1>BanglaFeel Translator</h1>
<p class="subtitle">Translate Romanized Bangla to Bengali with ease</p>
</header>
<div class="translation-box">
<div class="input-section">
<div class="input-header">
<label>
<span class="material-icons">language</span>
English
</label>
</div>
<textarea id="userInput" placeholder="Type or paste your text here..." maxlength="500"></textarea>
</div>
<div class="controls">
<div class="left-controls">
<button id="clearBtn" class="icon-btn" title="Clear text">
<span class="material-icons">clear</span>
</button>
</div>
<div class="right-controls">
<span class="char-count">0/500</span>
<button id="translateBtn" class="primary-btn">
<span class="material-icons">translate</span>
Translate
</button>
</div>
</div>
<div class="output-section">
<div class="output-header">
<label>
<span class="material-icons">translate</span>
Bengali
</label>
<button id="copyBtn" class="icon-btn" title="Copy translation">
<span class="material-icons">content_copy</span>
</button>
</div>
<div class="translation-result">
<p id="translationResult"></p>
<div id="sentimentContainer" style="display: none; margin-top: 15px;">
<strong>Sentiment:</strong> <span id="sentimentResult" class="sentiment-badge"></span>
</div>
<div class="loading-spinner" style="display: none;">
<div class="spinner"></div>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const userInput = document.getElementById('userInput');
const charCount = document.querySelector('.char-count');
const translateBtn = document.getElementById('translateBtn');
const clearBtn = document.getElementById('clearBtn');
const copyBtn = document.getElementById('copyBtn');
const translationResult = document.getElementById('translationResult');
const loadingSpinner = document.querySelector('.loading-spinner');
const sentimentContainer = document.getElementById('sentimentContainer');
const sentimentResult = document.getElementById('sentimentResult');
// Character counter
userInput.addEventListener('input', function() {
charCount.textContent = `${this.value.length}/500`;
});
// Clear button
clearBtn.addEventListener('click', function() {
userInput.value = '';
translationResult.textContent = '';
sentimentContainer.style.display = 'none';
sentimentResult.textContent = '';
sentimentResult.className = 'sentiment-badge';
charCount.textContent = '0/500';
});
// Copy button
copyBtn.addEventListener('click', function() {
if (translationResult.textContent) {
navigator.clipboard.writeText(translationResult.textContent)
.then(() => {
copyBtn.innerHTML = '<span class="material-icons">check</span>';
setTimeout(() => {
copyBtn.innerHTML = '<span class="material-icons">content_copy</span>';
}, 2000);
});
}
});
// Translation
translateBtn.addEventListener('click', async function() {
const text = userInput.value.trim();
if (!text) {
showToast('Please enter some text first.');
return;
}
// Show loading state
loadingSpinner.style.display = 'flex';
translateBtn.disabled = true;
translationResult.style.opacity = '0.5';
translationResult.textContent = '';
sentimentContainer.style.display = 'none';
try {
const response = await fetch('/translate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: text })
});
if (!response.ok) throw new Error(`Server error: ${response.status}`);
const data = await response.json();
translationResult.textContent = data.translation;
if (data.sentiment && data.sentiment !== 'Error' && data.sentiment !== 'Unknown') {
sentimentResult.textContent = data.sentiment;
sentimentResult.className = 'sentiment-badge'; // Reset classes
sentimentResult.classList.add(`sentiment-${data.sentiment.toLowerCase()}`);
sentimentContainer.style.display = 'flex';
}
translationResult.style.opacity = '1';
} catch (error) {
console.error('Error:', error);
translationResult.textContent = 'An error occurred during translation.';
showToast('Translation failed. Please try again.');
} finally {
loadingSpinner.style.display = 'none';
translateBtn.disabled = false;
}
});
function showToast(message) {
const toast = document.createElement('div');
toast.className = 'toast';
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => toast.remove(), 3000);
}
});
</script>
</body>
</html>
|