Clearwave48 commited on
Commit
8c3bee7
Β·
verified Β·
1 Parent(s): c9b267e

Create app_connected.html

Browse files
Files changed (1) hide show
  1. app_connected.html +550 -0
app_connected.html ADDED
@@ -0,0 +1,550 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6
+ <title>CleanVoice β€” Denoiser</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Syne:wght@400;600;800&family=JetBrains+Mono:wght@300;400;500&display=swap" rel="stylesheet"/>
8
+ <style>
9
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
10
+
11
+ :root {
12
+ --bg: #0a0a0f;
13
+ --surface: #11111a;
14
+ --surface2: #1a1a28;
15
+ --border: #2a2a3f;
16
+ --accent: #7c6aff;
17
+ --accent2: #ff6a9b;
18
+ --text: #e8e8f0;
19
+ --muted: #6b6b88;
20
+ --success: #4dffb4;
21
+ --danger: #ff4d6a;
22
+ --warning: #ffb347;
23
+ --radius: 16px;
24
+ }
25
+
26
+ body {
27
+ background: var(--bg); color: var(--text);
28
+ font-family: 'Syne', sans-serif;
29
+ min-height: 100vh; display: flex; flex-direction: column;
30
+ align-items: center; justify-content: flex-start;
31
+ padding: 48px 20px 80px; overflow-x: hidden;
32
+ }
33
+ body::before {
34
+ content: ''; position: fixed; inset: 0;
35
+ background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
36
+ pointer-events: none; z-index: 0; opacity: .4;
37
+ }
38
+ .orb { position: fixed; border-radius: 50%; filter: blur(120px); pointer-events: none; z-index: 0; }
39
+ .orb-1 { width: 500px; height: 500px; background: rgba(124,106,255,.12); top: -150px; left: -100px; }
40
+ .orb-2 { width: 400px; height: 400px; background: rgba(255,106,155,.1); bottom: -100px; right: -80px; }
41
+ .wrapper { position: relative; z-index: 1; width: 100%; max-width: 640px; }
42
+
43
+ header { text-align: center; margin-bottom: 48px; }
44
+ .logo-badge {
45
+ display: inline-flex; align-items: center; gap: 8px;
46
+ background: var(--surface2); border: 1px solid var(--border);
47
+ padding: 6px 14px; border-radius: 999px;
48
+ font-family: 'JetBrains Mono', monospace; font-size: 11px;
49
+ color: var(--accent); letter-spacing: .12em; text-transform: uppercase; margin-bottom: 20px;
50
+ }
51
+ .logo-badge span { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: pulse 2s infinite; }
52
+ h1 { font-size: clamp(2rem,6vw,3.2rem); font-weight: 800; line-height: 1.1;
53
+ background: linear-gradient(135deg,#fff 30%,var(--accent));
54
+ -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
55
+ .subtitle { color: var(--muted); font-size: .95rem; margin-top: 10px; letter-spacing: .02em; }
56
+
57
+ .card {
58
+ background: var(--surface); border: 1px solid var(--border);
59
+ border-radius: var(--radius); padding: 32px;
60
+ box-shadow: 0 0 0 1px rgba(255,255,255,.03), 0 24px 64px rgba(0,0,0,.5);
61
+ margin-bottom: 24px; animation: fadeUp .5s ease both;
62
+ }
63
+ .card-label {
64
+ font-family: 'JetBrains Mono', monospace; font-size: 10px;
65
+ letter-spacing: .15em; text-transform: uppercase; color: var(--muted);
66
+ margin-bottom: 20px; display: flex; align-items: center; gap: 8px;
67
+ }
68
+ .card-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }
69
+
70
+ .tabs {
71
+ display: grid; grid-template-columns: 1fr 1fr;
72
+ background: var(--bg); border: 1px solid var(--border);
73
+ border-radius: 10px; padding: 4px; margin-bottom: 28px; gap: 4px;
74
+ }
75
+ .tab-btn {
76
+ padding: 10px; border: none; border-radius: 7px;
77
+ background: transparent; color: var(--muted);
78
+ font-family: 'Syne', sans-serif; font-size: .875rem; font-weight: 600;
79
+ cursor: pointer; transition: all .2s; display: flex; align-items: center; justify-content: center; gap: 8px;
80
+ }
81
+ .tab-btn.active { background: var(--surface2); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.4); }
82
+ .tab-btn:hover:not(.active) { color: var(--text); }
83
+ .tab-panel { display: none; }
84
+ .tab-panel.active { display: block; animation: fadeIn .2s ease; }
85
+
86
+ .upload-zone {
87
+ border: 2px dashed var(--border); border-radius: 12px;
88
+ padding: 40px 24px; text-align: center; cursor: pointer; transition: all .25s;
89
+ }
90
+ .upload-zone:hover, .upload-zone.drag-over { border-color: var(--accent); background: rgba(124,106,255,.05); }
91
+ .upload-zone input[type=file] { display: none; }
92
+ .upload-icon { font-size: 2.5rem; margin-bottom: 12px; display: block; }
93
+ .upload-zone p { color: var(--muted); font-size: .875rem; }
94
+ .upload-zone strong { color: var(--text); }
95
+ .upload-zone .formats { font-family: 'JetBrains Mono', monospace; font-size: .75rem; color: var(--muted); margin-top: 8px; opacity: .7; }
96
+ .file-preview { display: none; align-items: center; gap: 12px; background: var(--surface2); border-radius: 10px; padding: 14px 16px; margin-top: 16px; }
97
+ .file-preview.visible { display: flex; }
98
+ .file-icon { font-size: 1.4rem; }
99
+ .file-info { flex: 1; min-width: 0; }
100
+ .file-name { font-size: .875rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
101
+ .file-size { font-family: 'JetBrains Mono', monospace; font-size: .75rem; color: var(--muted); }
102
+ .file-remove { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 4px; transition: color .2s; }
103
+ .file-remove:hover { color: var(--danger); }
104
+
105
+ .recorder-area { display: flex; flex-direction: column; align-items: center; gap: 24px; }
106
+ .record-btn {
107
+ width: 96px; height: 96px; border-radius: 50%; border: 2px solid var(--border);
108
+ background: var(--surface2); cursor: pointer; display: flex; align-items: center;
109
+ justify-content: center; font-size: 2rem; transition: all .2s; position: relative;
110
+ }
111
+ .record-btn:hover { border-color: var(--accent); transform: scale(1.04); }
112
+ .record-btn.recording { border-color: var(--danger); background: rgba(255,77,106,.1); animation: recPulse 1.4s ease-in-out infinite; }
113
+ .record-btn .rec-dot { width: 28px; height: 28px; border-radius: 50%; background: var(--danger); transition: all .3s; }
114
+ .record-btn.recording .rec-dot { border-radius: 6px; transform: scale(.8); }
115
+ .rec-timer { font-family: 'JetBrains Mono', monospace; font-size: 2rem; font-weight: 300; color: var(--text); letter-spacing: .08em; min-width: 100px; text-align: center; }
116
+ .rec-status { font-size: .8rem; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; font-family: 'JetBrains Mono', monospace; }
117
+ .rec-status.live { color: var(--danger); }
118
+ .waveform { display: flex; align-items: center; gap: 3px; height: 36px; opacity: 0; transition: opacity .3s; }
119
+ .waveform.active { opacity: 1; }
120
+ .wave-bar { width: 3px; border-radius: 99px; background: var(--accent); animation: wave .8s ease-in-out infinite; transform-origin: bottom; }
121
+ .wave-bar:nth-child(1) { animation-delay:0s; height:12px; }
122
+ .wave-bar:nth-child(2) { animation-delay:.1s; height:22px; }
123
+ .wave-bar:nth-child(3) { animation-delay:.2s; height:32px; }
124
+ .wave-bar:nth-child(4) { animation-delay:.1s; height:20px; }
125
+ .wave-bar:nth-child(5) { animation-delay:.3s; height:28px; }
126
+ .wave-bar:nth-child(6) { animation-delay:.15s; height:16px; }
127
+ .wave-bar:nth-child(7) { animation-delay:.25s; height:24px; }
128
+ .wave-bar:nth-child(8) { animation-delay:.05s; height:18px; }
129
+ .wave-bar:nth-child(9) { animation-delay:.35s; height:30px; }
130
+ .wave-bar:nth-child(10) { animation-delay:.2s; height:14px; }
131
+ .recorded-preview { width: 100%; display: none; flex-direction: column; gap: 12px; }
132
+ .recorded-preview.visible { display: flex; }
133
+ .recorded-preview audio { width: 100%; border-radius: 8px; filter: invert(1) hue-rotate(200deg); }
134
+ .recorded-actions { display: flex; gap: 8px; }
135
+ .btn-ghost { flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-family: 'Syne', sans-serif; font-size: .85rem; cursor: pointer; transition: all .2s; }
136
+ .btn-ghost:hover { border-color: var(--text); color: var(--text); }
137
+
138
+ .submit-btn {
139
+ width: 100%; padding: 16px;
140
+ background: linear-gradient(135deg, var(--accent), #a855f7);
141
+ border: none; border-radius: 12px; color: #fff;
142
+ font-family: 'Syne', sans-serif; font-size: 1rem; font-weight: 700;
143
+ letter-spacing: .04em; cursor: pointer; transition: all .25s;
144
+ display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 8px;
145
+ }
146
+ .submit-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(124,106,255,.35); }
147
+ .submit-btn:active { transform: translateY(0); }
148
+ .submit-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
149
+
150
+ /* ── result card ── */
151
+ .result-card { display: none; animation: fadeUp .4s ease both; }
152
+ .result-card.visible { display: block; }
153
+ .result-inner { display: flex; flex-direction: column; gap: 16px; }
154
+ .result-audio-label { font-family: 'JetBrains Mono', monospace; font-size: .75rem; color: var(--success); letter-spacing: .1em; text-transform: uppercase; }
155
+ .result-audio audio { width: 100%; border-radius: 8px; filter: invert(1) hue-rotate(130deg); }
156
+ .transcript-box {
157
+ background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px;
158
+ font-family: 'JetBrains Mono', monospace; font-size: .82rem; color: var(--text);
159
+ line-height: 1.7; white-space: pre-wrap; max-height: 200px; overflow-y: auto;
160
+ }
161
+ .copy-btn { align-self: flex-end; padding: 8px 16px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--muted); font-family: 'Syne', sans-serif; font-size: .8rem; cursor: pointer; transition: all .2s; }
162
+ .copy-btn:hover { color: var(--text); border-color: var(--text); }
163
+
164
+ /* ── pretty error box ── */
165
+ .error-card { display: none; animation: fadeUp .3s ease both; }
166
+ .error-card.visible { display: block; }
167
+ .error-header {
168
+ display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
169
+ }
170
+ .error-badge {
171
+ font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 500;
172
+ background: rgba(255,77,106,.15); color: var(--danger);
173
+ border: 1px solid rgba(255,77,106,.3); padding: 3px 10px; border-radius: 999px;
174
+ letter-spacing: .08em; text-transform: uppercase;
175
+ }
176
+ .error-title { font-size: .9rem; font-weight: 600; color: var(--danger); }
177
+ .error-json {
178
+ background: var(--bg); border: 1px solid rgba(255,77,106,.25);
179
+ border-radius: 10px; padding: 16px; overflow-x: auto;
180
+ font-family: 'JetBrains Mono', monospace; font-size: .8rem; line-height: 1.8;
181
+ }
182
+ /* JSON syntax highlighting */
183
+ .json-key { color: #7c6aff; }
184
+ .json-str { color: #4dffb4; }
185
+ .json-num { color: #ffb347; }
186
+ .json-bool { color: #ff6a9b; }
187
+ .json-null { color: #6b6b88; }
188
+ .json-brace { color: var(--muted); }
189
+
190
+ /* ── progress bar ── */
191
+ .progress-track { height: 3px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 12px; display: none; }
192
+ .progress-track.active { display: block; }
193
+ .progress-fill { height: 100%; background: linear-gradient(90deg,var(--accent),#a855f7); border-radius: 99px; width: 0%; transition: width .4s ease; }
194
+
195
+ /* ── status steps ── */
196
+ .status-steps { display: none; flex-direction: column; gap: 6px; margin-top: 12px; }
197
+ .status-steps.active { display: flex; }
198
+ .status-step {
199
+ display: flex; align-items: center; gap: 10px;
200
+ font-family: 'JetBrains Mono', monospace; font-size: .75rem; color: var(--muted);
201
+ transition: color .3s;
202
+ }
203
+ .status-step.done { color: var(--success); }
204
+ .status-step.active-step { color: var(--accent); }
205
+ .step-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
206
+
207
+ .toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--surface2); border: 1px solid var(--border); padding: 12px 20px; border-radius: 10px; font-size: .85rem; opacity: 0; transition: all .3s; pointer-events: none; white-space: nowrap; z-index: 100; }
208
+ .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
209
+
210
+ @keyframes fadeUp { from { opacity:0; transform:translateY(18px); } to { opacity:1; transform:translateY(0); } }
211
+ @keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
212
+ @keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.4; } }
213
+ @keyframes recPulse { 0%,100% { box-shadow:0 0 0 0 rgba(255,77,106,.4); } 50% { box-shadow:0 0 0 14px rgba(255,77,106,0); } }
214
+ @keyframes wave { 0%,100% { transform:scaleY(1); } 50% { transform:scaleY(.35); } }
215
+ </style>
216
+ </head>
217
+ <body>
218
+ <div class="orb orb-1"></div>
219
+ <div class="orb orb-2"></div>
220
+
221
+ <div class="wrapper">
222
+ <header>
223
+ <div class="logo-badge"><span></span> CleanVoice AI</div>
224
+ <h1>Audio Denoiser</h1>
225
+ <p class="subtitle">Remove noise, fillers & stutters from your recordings</p>
226
+ </header>
227
+
228
+ <!-- input card -->
229
+ <div class="card">
230
+ <div class="card-label">Input Audio</div>
231
+ <div class="tabs">
232
+ <button class="tab-btn active" data-tab="upload">
233
+ <svg width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
234
+ Upload File
235
+ </button>
236
+ <button class="tab-btn" data-tab="record">
237
+ <svg width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M12 2a3 3 0 013 3v7a3 3 0 01-6 0V5a3 3 0 013-3z"/><path d="M19 10v2a7 7 0 01-14 0v-2"/><line x1="12" y1="19" x2="12" y2="22"/></svg>
238
+ Record
239
+ </button>
240
+ </div>
241
+
242
+ <div class="tab-panel active" id="panel-upload">
243
+ <div class="upload-zone" id="dropZone">
244
+ <input type="file" id="fileInput" accept="audio/*,.wav,.mp3,.m4a,.ogg,.flac,.webm"/>
245
+ <span class="upload-icon">🎡</span>
246
+ <p><strong>Drop your audio file here</strong><br>or click to browse</p>
247
+ <p class="formats">WAV Β· MP3 Β· M4A Β· OGG Β· FLAC Β· WEBM</p>
248
+ </div>
249
+ <div class="file-preview" id="filePreview">
250
+ <span class="file-icon">🎧</span>
251
+ <div class="file-info">
252
+ <div class="file-name" id="fileName">β€”</div>
253
+ <div class="file-size" id="fileSize">β€”</div>
254
+ </div>
255
+ <button class="file-remove" id="fileRemove" title="Remove">βœ•</button>
256
+ </div>
257
+ </div>
258
+
259
+ <div class="tab-panel" id="panel-record">
260
+ <div class="recorder-area">
261
+ <div class="waveform" id="waveform">
262
+ <div class="wave-bar"></div><div class="wave-bar"></div><div class="wave-bar"></div>
263
+ <div class="wave-bar"></div><div class="wave-bar"></div><div class="wave-bar"></div>
264
+ <div class="wave-bar"></div><div class="wave-bar"></div><div class="wave-bar"></div>
265
+ <div class="wave-bar"></div>
266
+ </div>
267
+ <button class="record-btn" id="recordBtn"><div class="rec-dot"></div></button>
268
+ <div class="rec-timer" id="recTimer">00:00</div>
269
+ <div class="rec-status" id="recStatus">tap to record</div>
270
+ <div class="recorded-preview" id="recordedPreview">
271
+ <audio id="recordedAudio" controls></audio>
272
+ <div class="recorded-actions">
273
+ <button class="btn-ghost" id="reRecordBtn">β†Ί Re-record</button>
274
+ </div>
275
+ </div>
276
+ </div>
277
+ </div>
278
+ </div>
279
+
280
+ <button class="submit-btn" id="submitBtn" disabled>
281
+ <svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><polygon points="5 3 19 12 5 21 5 3"/></svg>
282
+ Process Audio
283
+ </button>
284
+
285
+ <!-- progress -->
286
+ <div class="progress-track" id="progressTrack"><div class="progress-fill" id="progressFill"></div></div>
287
+ <div class="status-steps" id="statusSteps">
288
+ <div class="status-step" id="step1"><div class="step-dot"></div> Uploading audio…</div>
289
+ <div class="status-step" id="step2"><div class="step-dot"></div> Converting to WAV…</div>
290
+ <div class="status-step" id="step3"><div class="step-dot"></div> Running denoiser…</div>
291
+ <div class="status-step" id="step4"><div class="step-dot"></div> Cleaning transcript…</div>
292
+ </div>
293
+
294
+ <!-- result -->
295
+ <div class="card result-card" id="resultCard" style="margin-top:24px;">
296
+ <div class="card-label">Output</div>
297
+ <div class="result-inner">
298
+ <div>
299
+ <div class="result-audio-label">✦ Cleaned Audio</div>
300
+ <div class="result-audio" style="margin-top:10px;"><audio id="resultAudio" controls></audio></div>
301
+ </div>
302
+ <div>
303
+ <div class="result-audio-label" style="color:var(--accent)">✦ Transcript</div>
304
+ <div class="transcript-box" id="transcriptBox">β€”</div>
305
+ </div>
306
+ <button class="copy-btn" id="copyBtn">Copy Transcript</button>
307
+ </div>
308
+ </div>
309
+
310
+ <!-- pretty error -->
311
+ <div class="card error-card" id="errorCard" style="margin-top:24px; border-color: rgba(255,77,106,.25);">
312
+ <div class="card-label" style="color: var(--danger)">Error Response</div>
313
+ <div class="error-header">
314
+ <span class="error-badge" id="errorStatus">404</span>
315
+ <span class="error-title" id="errorTitle">Not Found</span>
316
+ </div>
317
+ <pre class="error-json" id="errorJson"></pre>
318
+ </div>
319
+ </div>
320
+
321
+ <div class="toast" id="toast"></div>
322
+
323
+ <script>
324
+ // ── CONFIG β€” change this to your HF Space API endpoint ──
325
+ const API_BASE = 'https://YOUR-HF-SPACE.hf.space'; // e.g. https://yourname-denoiser.hf.space
326
+ const DENOISE_ENDPOINT = `${API_BASE}/denoise`; // adjust to your route
327
+
328
+ /* ──────────────────── TABS ──────────────────── */
329
+ document.querySelectorAll('.tab-btn').forEach(btn => {
330
+ btn.addEventListener('click', () => {
331
+ document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
332
+ document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
333
+ btn.classList.add('active');
334
+ document.getElementById('panel-' + btn.dataset.tab).classList.add('active');
335
+ clearAudio();
336
+ });
337
+ });
338
+
339
+ /* ──────────────────── UPLOAD ──────────────────── */
340
+ let uploadedFile = null;
341
+ const dropZone = document.getElementById('dropZone');
342
+ const fileInput = document.getElementById('fileInput');
343
+ const filePreview = document.getElementById('filePreview');
344
+ const fileName = document.getElementById('fileName');
345
+ const fileSize = document.getElementById('fileSize');
346
+
347
+ dropZone.addEventListener('click', () => fileInput.click());
348
+ dropZone.addEventListener('dragover', e => { e.preventDefault(); dropZone.classList.add('drag-over'); });
349
+ dropZone.addEventListener('dragleave', () => dropZone.classList.remove('drag-over'));
350
+ dropZone.addEventListener('drop', e => {
351
+ e.preventDefault(); dropZone.classList.remove('drag-over');
352
+ if (e.dataTransfer.files[0]) setFile(e.dataTransfer.files[0]);
353
+ });
354
+ fileInput.addEventListener('change', () => { if (fileInput.files[0]) setFile(fileInput.files[0]); });
355
+ document.getElementById('fileRemove').addEventListener('click', () => {
356
+ uploadedFile = null; filePreview.classList.remove('visible'); updateSubmit();
357
+ });
358
+
359
+ function setFile(f) {
360
+ uploadedFile = f;
361
+ fileName.textContent = f.name;
362
+ fileSize.textContent = (f.size / 1024 / 1024).toFixed(2) + ' MB';
363
+ filePreview.classList.add('visible');
364
+ updateSubmit();
365
+ }
366
+
367
+ /* ──────────────────── RECORDER ──────────────────── */
368
+ let mediaRecorder, recordedBlob, timerInterval, seconds = 0;
369
+ const recordBtn = document.getElementById('recordBtn');
370
+ const recTimer = document.getElementById('recTimer');
371
+ const recStatus = document.getElementById('recStatus');
372
+ const waveform = document.getElementById('waveform');
373
+ const recordedPreview = document.getElementById('recordedPreview');
374
+ const recordedAudio = document.getElementById('recordedAudio');
375
+
376
+ recordBtn.addEventListener('click', async () => {
377
+ if (!mediaRecorder || mediaRecorder.state === 'inactive') {
378
+ try {
379
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
380
+ mediaRecorder = new MediaRecorder(stream);
381
+ const chunks = [];
382
+ mediaRecorder.ondataavailable = e => chunks.push(e.data);
383
+ mediaRecorder.onstop = () => {
384
+ recordedBlob = new Blob(chunks, { type: 'audio/webm' });
385
+ recordedAudio.src = URL.createObjectURL(recordedBlob);
386
+ recordedPreview.classList.add('visible');
387
+ updateSubmit();
388
+ stream.getTracks().forEach(t => t.stop());
389
+ };
390
+ mediaRecorder.start();
391
+ recordBtn.classList.add('recording');
392
+ waveform.classList.add('active');
393
+ recStatus.textContent = 'recording…'; recStatus.classList.add('live');
394
+ seconds = 0; recTimer.textContent = '00:00';
395
+ timerInterval = setInterval(() => {
396
+ seconds++;
397
+ recTimer.textContent = String(Math.floor(seconds/60)).padStart(2,'0') + ':' + String(seconds%60).padStart(2,'0');
398
+ }, 1000);
399
+ } catch { showToast('Microphone access denied'); }
400
+ } else {
401
+ mediaRecorder.stop(); clearInterval(timerInterval);
402
+ recordBtn.classList.remove('recording'); waveform.classList.remove('active');
403
+ recStatus.textContent = 'recording saved'; recStatus.classList.remove('live');
404
+ }
405
+ });
406
+
407
+ document.getElementById('reRecordBtn').addEventListener('click', () => {
408
+ recordedBlob = null; recordedPreview.classList.remove('visible');
409
+ recordedAudio.src = ''; recStatus.textContent = 'tap to record'; recTimer.textContent = '00:00';
410
+ updateSubmit();
411
+ });
412
+
413
+ function clearAudio() {
414
+ uploadedFile = null; recordedBlob = null;
415
+ filePreview.classList.remove('visible'); recordedPreview.classList.remove('visible');
416
+ updateSubmit();
417
+ }
418
+ function updateSubmit() {
419
+ document.getElementById('submitBtn').disabled = !(uploadedFile || recordedBlob);
420
+ }
421
+
422
+ /* ──────────────────── PRETTY JSON ──────────────────── */
423
+ function syntaxHighlight(obj) {
424
+ const json = JSON.stringify(obj, null, 2);
425
+ return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, match => {
426
+ if (/^"/.test(match)) {
427
+ if (/:$/.test(match)) return `<span class="json-key">${match}</span>`;
428
+ return `<span class="json-str">${match}</span>`;
429
+ }
430
+ if (/true|false/.test(match)) return `<span class="json-bool">${match}</span>`;
431
+ if (/null/.test(match)) return `<span class="json-null">${match}</span>`;
432
+ return `<span class="json-num">${match}</span>`;
433
+ });
434
+ }
435
+
436
+ function showError(statusCode, data) {
437
+ document.getElementById('resultCard').classList.remove('visible');
438
+ const card = document.getElementById('errorCard');
439
+ const badge = document.getElementById('errorStatus');
440
+ const title = document.getElementById('errorTitle');
441
+ const jsonEl = document.getElementById('errorJson');
442
+
443
+ badge.textContent = statusCode;
444
+ // derive human title
445
+ const titles = { 400:'Bad Request', 401:'Unauthorized', 403:'Forbidden',
446
+ 404:'Not Found', 422:'Unprocessable Entity', 500:'Internal Server Error' };
447
+ title.textContent = data?.detail || titles[statusCode] || 'Error';
448
+ jsonEl.innerHTML = syntaxHighlight(data);
449
+ card.classList.add('visible');
450
+ card.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
451
+ }
452
+
453
+ /* ──────────────────── PROGRESS ──────────────────── */
454
+ function setStep(n) {
455
+ [1,2,3,4].forEach(i => {
456
+ const el = document.getElementById('step' + i);
457
+ el.classList.remove('done','active-step');
458
+ if (i < n) el.classList.add('done');
459
+ if (i === n) el.classList.add('active-step');
460
+ });
461
+ document.getElementById('progressFill').style.width = ((n-1)/3 * 100) + '%';
462
+ }
463
+ function showProgress(show) {
464
+ document.getElementById('progressTrack').classList.toggle('active', show);
465
+ document.getElementById('statusSteps').classList.toggle('active', show);
466
+ if (!show) document.getElementById('progressFill').style.width = '0%';
467
+ }
468
+
469
+ /* ──────────────────── SUBMIT ──────────────────── */
470
+ const submitBtn = document.getElementById('submitBtn');
471
+
472
+ submitBtn.addEventListener('click', async () => {
473
+ submitBtn.disabled = true;
474
+ submitBtn.innerHTML = `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg> Processing…`;
475
+
476
+ document.getElementById('resultCard').classList.remove('visible');
477
+ document.getElementById('errorCard').classList.remove('visible');
478
+ showProgress(true);
479
+ setStep(1);
480
+
481
+ const formData = new FormData();
482
+ const audioBlob = uploadedFile || recordedBlob;
483
+ const audioName = uploadedFile ? uploadedFile.name : 'recording.webm';
484
+ formData.append('file', audioBlob, audioName);
485
+
486
+ try {
487
+ setStep(2);
488
+ await new Promise(r => setTimeout(r, 400)); // slight delay for UX step visibility
489
+ setStep(3);
490
+
491
+ const response = await fetch(DENOISE_ENDPOINT, {
492
+ method: 'POST',
493
+ body: formData,
494
+ });
495
+
496
+ const contentType = response.headers.get('Content-Type') || '';
497
+ let data;
498
+ if (contentType.includes('application/json')) {
499
+ data = await response.json();
500
+ } else {
501
+ data = { detail: await response.text() };
502
+ }
503
+
504
+ if (!response.ok) {
505
+ // ── pretty print the error ──
506
+ showProgress(false);
507
+ showError(response.status, data);
508
+ } else {
509
+ setStep(4);
510
+
511
+ // ── happy path: expect { audio_url, transcript } ──
512
+ const resultAudio = document.getElementById('resultAudio');
513
+ const transcriptBox = document.getElementById('transcriptBox');
514
+ const resultCard = document.getElementById('resultCard');
515
+
516
+ if (data.audio_url) {
517
+ resultAudio.src = data.audio_url;
518
+ } else if (data.audio_base64) {
519
+ resultAudio.src = 'data:audio/wav;base64,' + data.audio_base64;
520
+ }
521
+ transcriptBox.textContent = data.transcript || data.text || JSON.stringify(data, null, 2);
522
+ showProgress(false);
523
+ resultCard.classList.add('visible');
524
+ resultCard.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
525
+ }
526
+ } catch (err) {
527
+ showProgress(false);
528
+ showError('Network', { detail: err.message, type: 'NetworkError' });
529
+ }
530
+
531
+ submitBtn.disabled = false;
532
+ submitBtn.innerHTML = `<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><polygon points="5 3 19 12 5 21 5 3"/></svg> Process Audio`;
533
+ updateSubmit();
534
+ });
535
+
536
+ document.getElementById('copyBtn').addEventListener('click', () => {
537
+ navigator.clipboard.writeText(document.getElementById('transcriptBox').textContent)
538
+ .then(() => showToast('Copied!'));
539
+ });
540
+
541
+ /* ──────────────────── TOAST ──────────────────── */
542
+ const toast = document.getElementById('toast');
543
+ function showToast(msg) {
544
+ toast.textContent = msg;
545
+ toast.classList.add('show');
546
+ setTimeout(() => toast.classList.remove('show'), 2500);
547
+ }
548
+ </script>
549
+ </body>
550
+ </html>