-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfront.html
More file actions
366 lines (307 loc) · 19.2 KB
/
front.html
File metadata and controls
366 lines (307 loc) · 19.2 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MetricGAN+ Enhancer | DevSoc'26</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/lucide@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700;900&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
body { font-family: 'Inter', sans-serif; }
.font-mono { font-family: 'JetBrains Mono', monospace; }
@keyframes pulse-glow {
0%, 100% { box-shadow: 0 0 20px rgba(168, 85, 247, 0.2); }
50% { box-shadow: 0 0 40px rgba(168, 85, 247, 0.6); }
}
.animate-pulse-glow { animation: pulse-glow 2s infinite; }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #0f172a; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }
</style>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
slate: { 950: '#020617' }
}
}
}
}
</script>
</head>
<body class="min-h-screen bg-slate-950 text-slate-100 overflow-hidden relative selection:bg-cyan-500/30">
<!-- Background Decor -->
<div class="absolute top-0 left-0 w-full h-full overflow-hidden pointer-events-none z-0">
<div class="absolute top-[-10%] right-[-10%] w-[500px] h-[500px] bg-cyan-500/10 rounded-full blur-[100px]"></div>
<div class="absolute bottom-[-10%] left-[-10%] w-[500px] h-[500px] bg-purple-500/10 rounded-full blur-[100px]"></div>
<div class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-full h-full bg-[radial-gradient(ellipse_at_center,_var(--tw-gradient-stops))] from-slate-900/50 via-slate-950 to-slate-950"></div>
</div>
<!-- Main Content Container -->
<div class="relative z-10 flex flex-col h-screen max-w-6xl mx-auto p-6">
<!-- Header -->
<header class="flex items-center justify-between mb-8 border-b border-slate-800 pb-4">
<div class="flex items-center gap-3">
<div class="bg-gradient-to-br from-cyan-400 to-blue-600 p-2.5 rounded-lg shadow-lg shadow-cyan-500/20">
<i data-lucide="activity" class="w-6 h-6 text-white"></i>
</div>
<div>
<h1 class="text-2xl font-bold tracking-tight text-white">
MetricGAN+ <span class="text-cyan-400">Enhancer</span>
</h1>
<p class="text-xs text-slate-400 font-mono uppercase tracking-widest">
DevSoc'26 Audio Processor • Indian Edition
</p>
</div>
</div>
<!-- Backend Status -->
<div class="flex items-center gap-2 bg-slate-900/50 px-4 py-2 rounded-lg border border-slate-800">
<div id="backend-status" class="w-2 h-2 rounded-full bg-slate-600"></div>
<span id="backend-text" class="text-xs font-mono text-slate-500">Checking...</span>
</div>
</header>
<!-- Main Content Area -->
<main class="flex-1 relative">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 h-full">
<!-- Left: Upload -->
<div id="drop-zone" class="flex flex-col items-center justify-center border-2 border-dashed border-slate-700 rounded-2xl transition-all duration-300 relative overflow-hidden group hover:border-cyan-500/50 hover:bg-slate-900 cursor-pointer">
<input type="file" id="file-input" accept="audio/wav,audio/x-wav,audio/wave" class="absolute inset-0 w-full h-full opacity-0 cursor-pointer z-10">
<div class="text-center p-8 pointer-events-none z-0">
<div id="upload-icon-container" class="w-20 h-20 rounded-full bg-slate-800 text-slate-500 flex items-center justify-center mx-auto mb-6 transition-all duration-500 group-hover:scale-110 group-hover:text-cyan-400">
<i id="upload-icon" data-lucide="upload" class="w-10 h-10"></i>
</div>
<h3 id="file-name" class="text-xl font-bold text-white mb-2">Drop WAV File Here</h3>
<p id="file-status" class="text-slate-400 max-w-xs mx-auto">
Supports WAV files only (16kHz recommended).<br>
Drag and drop or click to browse.
</p>
</div>
</div>
<!-- Right: Controls -->
<div class="flex flex-col gap-6">
<!-- Action Card -->
<div class="bg-slate-900 border border-slate-800 rounded-2xl p-6 shadow-xl">
<div class="flex justify-between items-center mb-6">
<h2 class="text-lg font-semibold flex items-center gap-2">
<i data-lucide="cpu" class="w-5 h-5 text-cyan-400"></i> Processing Unit
</h2>
<span id="processing-badge" class="text-xs text-cyan-400 animate-pulse hidden">ENHANCING...</span>
</div>
<button id="btn-enhance" onclick="handleEnhance()" disabled class="w-full py-4 rounded-xl font-bold text-lg tracking-wide transition-all duration-200 flex items-center justify-center gap-3 bg-slate-800 text-slate-600 cursor-not-allowed">
<i data-lucide="zap" class="w-5 h-5 fill-current"></i> RUN ENHANCEMENT
</button>
<div id="error-msg" class="hidden mt-4 p-3 bg-red-900/20 border border-red-800/50 rounded-lg flex items-start gap-3 text-red-400 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4 mt-0.5 flex-shrink-0"></i>
<div>
<span id="error-text"></span>
<div id="error-details" class="text-xs text-red-300 mt-1 font-mono"></div>
</div>
</div>
<div id="success-msg" class="hidden mt-4 p-3 bg-emerald-900/20 border border-emerald-800/50 rounded-lg flex items-center gap-3 text-emerald-400 text-sm">
<i data-lucide="check-circle" class="w-4 h-4"></i>
<span>Enhancement complete! Download your file below.</span>
</div>
</div>
<!-- Players -->
<div class="flex-1 space-y-4">
<!-- Original -->
<div id="player-original-container" class="p-4 rounded-xl border border-slate-800 bg-slate-900/50 opacity-50 transition-all duration-500">
<div class="text-xs font-mono text-slate-500 mb-2 uppercase tracking-wider flex items-center justify-between">
<span>Original Input</span>
<span id="original-size" class="text-[10px]"></span>
</div>
<audio id="audio-original" controls class="w-full h-10 accent-cyan-500"></audio>
</div>
<!-- Enhanced -->
<div id="player-enhanced-container" class="p-4 rounded-xl border border-slate-800 bg-slate-900/50 opacity-50 transition-all duration-500 relative overflow-hidden">
<div class="text-xs font-mono text-cyan-400 mb-2 uppercase tracking-wider flex items-center justify-between">
<span class="flex items-center gap-2">
Enhanced Output
<span id="ai-badge" class="hidden bg-cyan-500/20 px-1.5 py-0.5 rounded text-[9px] font-bold">MetricGAN+ ML</span>
</span>
<button id="btn-download" onclick="downloadEnhanced()" class="hidden text-[10px] bg-cyan-500/10 hover:bg-cyan-500/20 px-2 py-1 rounded transition-colors flex items-center gap-1">
<i data-lucide="download" class="w-3 h-3"></i> DOWNLOAD
</button>
</div>
<audio id="audio-enhanced" controls class="w-full h-10 accent-cyan-500"></audio>
</div>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="mt-6 text-center text-slate-600 text-xs font-mono">
PYTORCH BACKEND • METRICGAN+ TRAINED ON INDIAN CORPUS
</footer>
</div>
<!-- LOGIC -->
<script>
// --- CONFIG ---
const API_BASE = "http://127.0.0.1:8000";
// --- STATE ---
let currentFile = null;
let enhancedBlob = null;
// --- INIT ---
document.addEventListener('DOMContentLoaded', () => {
lucide.createIcons();
checkBackendStatus();
});
// --- BACKEND HEALTH CHECK ---
async function checkBackendStatus() {
const statusDot = document.getElementById('backend-status');
const statusText = document.getElementById('backend-text');
try {
// Try a simple request to check if backend is alive
await axios.get(`${API_BASE}/docs`, { timeout: 3000 });
statusDot.className = "w-2 h-2 rounded-full bg-emerald-500 animate-pulse";
statusText.innerText = "Connected";
statusText.className = "text-xs font-mono text-emerald-400";
} catch(e) {
statusDot.className = "w-2 h-2 rounded-full bg-red-500";
statusText.innerText = "Offline";
statusText.className = "text-xs font-mono text-red-400";
// Show error message
const errorMsg = document.getElementById('error-msg');
const errorText = document.getElementById('error-text');
const errorDetails = document.getElementById('error-details');
errorMsg.classList.remove('hidden');
errorText.innerText = "Backend server is not running.";
errorDetails.innerText = "Start the FastAPI server: python app.py";
}
}
// --- FILE HANDLING ---
const fileInput = document.getElementById('file-input');
const dropZone = document.getElementById('drop-zone');
fileInput.addEventListener('change', (e) => {
if (e.target.files[0]) {
handleFileSelection(e.target.files[0]);
}
});
// Drag and drop support
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('border-cyan-500', 'bg-cyan-950/20');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('border-cyan-500', 'bg-cyan-950/20');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('border-cyan-500', 'bg-cyan-950/20');
if (e.dataTransfer.files[0]) {
handleFileSelection(e.dataTransfer.files[0]);
}
});
function handleFileSelection(file) {
// Validate WAV file
if (!file.type.includes('wav') && !file.name.endsWith('.wav')) {
alert('Please upload a WAV file only.');
return;
}
currentFile = file;
// Update UI
document.getElementById('file-name').innerText = file.name;
document.getElementById('file-status').innerText = "Ready to enhance. Click the button below.";
document.getElementById('original-size').innerText = formatFileSize(file.size);
// Highlight drop zone
dropZone.className = "flex flex-col items-center justify-center border-2 border-dashed rounded-2xl transition-all duration-300 relative overflow-hidden group border-cyan-500/50 bg-cyan-950/10 cursor-pointer";
// Change Icon
const iconContainer = document.getElementById('upload-icon-container');
iconContainer.className = "w-20 h-20 rounded-full flex items-center justify-center mx-auto mb-6 transition-all duration-500 bg-cyan-500 text-white shadow-lg shadow-cyan-500/40";
document.getElementById('upload-icon').setAttribute('data-lucide', 'file-audio');
lucide.createIcons();
// Set Original Audio
const url = URL.createObjectURL(file);
const audioOriginal = document.getElementById('audio-original');
audioOriginal.src = url;
document.getElementById('player-original-container').className = "p-4 rounded-xl border border-slate-700 bg-slate-900 opacity-100 transition-all duration-500";
// Enable Button
const btn = document.getElementById('btn-enhance');
btn.disabled = false;
btn.className = "w-full py-4 rounded-xl font-bold text-lg tracking-wide transition-all duration-200 flex items-center justify-center gap-3 bg-gradient-to-r from-cyan-600 to-blue-600 text-white hover:shadow-lg hover:shadow-cyan-500/25 hover:scale-[1.02] cursor-pointer";
// Reset Enhanced
document.getElementById('audio-enhanced').src = "";
document.getElementById('player-enhanced-container').className = "p-4 rounded-xl border border-slate-800 bg-slate-900/50 opacity-50 transition-all duration-500 relative overflow-hidden";
document.getElementById('ai-badge').classList.add('hidden');
document.getElementById('btn-download').classList.add('hidden');
document.getElementById('error-msg').classList.add('hidden');
document.getElementById('success-msg').classList.add('hidden');
enhancedBlob = null;
}
async function handleEnhance() {
if (!currentFile) return;
const btn = document.getElementById('btn-enhance');
const badge = document.getElementById('processing-badge');
const errorMsg = document.getElementById('error-msg');
const successMsg = document.getElementById('success-msg');
// Reset messages
errorMsg.classList.add('hidden');
successMsg.classList.add('hidden');
// Loading State
btn.disabled = true;
btn.innerHTML = `<div class="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin"></div> Processing with MetricGAN+...`;
btn.className = "w-full py-4 rounded-xl font-bold text-lg tracking-wide transition-all duration-200 flex items-center justify-center gap-3 bg-cyan-900/50 text-cyan-200 cursor-wait";
badge.classList.remove('hidden');
const formData = new FormData();
formData.append('file', currentFile);
try {
const response = await axios.post(`${API_BASE}/enhance`, formData, {
responseType: 'blob',
timeout: 120000 // 2 minutes timeout for processing
});
enhancedBlob = new Blob([response.data], { type: 'audio/wav' });
const url = URL.createObjectURL(enhancedBlob);
// Success State
const audioEnhanced = document.getElementById('audio-enhanced');
audioEnhanced.src = url;
document.getElementById('player-enhanced-container').className = "p-4 rounded-xl border border-cyan-500/50 bg-slate-900 opacity-100 shadow-lg shadow-cyan-900/20 transition-all duration-500 relative overflow-hidden";
document.getElementById('ai-badge').classList.remove('hidden');
document.getElementById('btn-download').classList.remove('hidden');
successMsg.classList.remove('hidden');
} catch (err) {
console.error(err);
const errorText = document.getElementById('error-text');
const errorDetails = document.getElementById('error-details');
errorMsg.classList.remove('hidden');
if (err.code === 'ECONNABORTED') {
errorText.innerText = "Request timeout. File may be too large.";
errorDetails.innerText = "";
} else if (err.response) {
errorText.innerText = `Server error (${err.response.status})`;
errorDetails.innerText = err.response.data?.error || "Check console for details";
} else if (err.request) {
errorText.innerText = "Cannot reach backend server.";
errorDetails.innerText = "Make sure the server is running on port 8000";
} else {
errorText.innerText = "Enhancement failed.";
errorDetails.innerText = err.message;
}
} finally {
// Reset Button
badge.classList.add('hidden');
btn.disabled = false;
btn.innerHTML = `<i data-lucide="zap" class="w-5 h-5 fill-current"></i> RUN ENHANCEMENT`;
btn.className = "w-full py-4 rounded-xl font-bold text-lg tracking-wide transition-all duration-200 flex items-center justify-center gap-3 bg-gradient-to-r from-cyan-600 to-blue-600 text-white hover:shadow-lg hover:shadow-cyan-500/25 hover:scale-[1.02] cursor-pointer";
lucide.createIcons();
}
}
function downloadEnhanced() {
if (!enhancedBlob) return;
const link = document.createElement('a');
link.href = URL.createObjectURL(enhancedBlob);
link.download = `enhanced_${currentFile.name}`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function formatFileSize(bytes) {
if (bytes < 1024) return bytes + ' B';
if (bytes < 1048576) return (bytes / 1024).toFixed(1) + ' KB';
return (bytes / 1048576).toFixed(1) + ' MB';
}
</script>
</body>
</html>