Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload folder using huggingface_hub
Browse files- index.html +29 -2
index.html
CHANGED
@@ -183,8 +183,6 @@
|
|
183 |
top: 20px;
|
184 |
left: 50%;
|
185 |
transform: translateX(-50%);
|
186 |
-
background-color: #f44336;
|
187 |
-
color: white;
|
188 |
padding: 16px 24px;
|
189 |
border-radius: 4px;
|
190 |
font-size: 14px;
|
@@ -192,6 +190,16 @@
|
|
192 |
display: none;
|
193 |
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
194 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
</style>
|
196 |
</head>
|
197 |
|
@@ -278,6 +286,7 @@
|
|
278 |
function showError(message) {
|
279 |
const toast = document.getElementById('error-toast');
|
280 |
toast.textContent = message;
|
|
|
281 |
toast.style.display = 'block';
|
282 |
|
283 |
// Hide toast after 5 seconds
|
@@ -318,6 +327,18 @@
|
|
318 |
const config = __RTC_CONFIGURATION__;
|
319 |
peerConnection = new RTCPeerConnection(config);
|
320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
try {
|
322 |
const stream = await navigator.mediaDevices.getUserMedia({
|
323 |
audio: true
|
@@ -351,6 +372,11 @@
|
|
351 |
|
352 |
peerConnection.addEventListener('connectionstatechange', () => {
|
353 |
console.log('connectionstatechange', peerConnection.connectionState);
|
|
|
|
|
|
|
|
|
|
|
354 |
updateButtonState();
|
355 |
});
|
356 |
|
@@ -386,6 +412,7 @@
|
|
386 |
addMessage(eventJson.message.role, eventJson.audio ?? eventJson.message.content);
|
387 |
});
|
388 |
} catch (err) {
|
|
|
389 |
console.error('Error setting up WebRTC:', err);
|
390 |
showError('Failed to establish connection. Please try again.');
|
391 |
stop();
|
|
|
183 |
top: 20px;
|
184 |
left: 50%;
|
185 |
transform: translateX(-50%);
|
|
|
|
|
186 |
padding: 16px 24px;
|
187 |
border-radius: 4px;
|
188 |
font-size: 14px;
|
|
|
190 |
display: none;
|
191 |
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
192 |
}
|
193 |
+
|
194 |
+
.toast.error {
|
195 |
+
background-color: #f44336;
|
196 |
+
color: white;
|
197 |
+
}
|
198 |
+
|
199 |
+
.toast.warning {
|
200 |
+
background-color: #ffd700;
|
201 |
+
color: black;
|
202 |
+
}
|
203 |
</style>
|
204 |
</head>
|
205 |
|
|
|
286 |
function showError(message) {
|
287 |
const toast = document.getElementById('error-toast');
|
288 |
toast.textContent = message;
|
289 |
+
toast.className = 'toast error';
|
290 |
toast.style.display = 'block';
|
291 |
|
292 |
// Hide toast after 5 seconds
|
|
|
327 |
const config = __RTC_CONFIGURATION__;
|
328 |
peerConnection = new RTCPeerConnection(config);
|
329 |
|
330 |
+
const timeoutId = setTimeout(() => {
|
331 |
+
const toast = document.getElementById('error-toast');
|
332 |
+
toast.textContent = "Connection is taking longer than usual. Are you on a VPN?";
|
333 |
+
toast.className = 'toast warning';
|
334 |
+
toast.style.display = 'block';
|
335 |
+
|
336 |
+
// Hide warning after 5 seconds
|
337 |
+
setTimeout(() => {
|
338 |
+
toast.style.display = 'none';
|
339 |
+
}, 5000);
|
340 |
+
}, 5000);
|
341 |
+
|
342 |
try {
|
343 |
const stream = await navigator.mediaDevices.getUserMedia({
|
344 |
audio: true
|
|
|
372 |
|
373 |
peerConnection.addEventListener('connectionstatechange', () => {
|
374 |
console.log('connectionstatechange', peerConnection.connectionState);
|
375 |
+
if (peerConnection.connectionState === 'connected') {
|
376 |
+
clearTimeout(timeoutId);
|
377 |
+
const toast = document.getElementById('error-toast');
|
378 |
+
toast.style.display = 'none';
|
379 |
+
}
|
380 |
updateButtonState();
|
381 |
});
|
382 |
|
|
|
412 |
addMessage(eventJson.message.role, eventJson.audio ?? eventJson.message.content);
|
413 |
});
|
414 |
} catch (err) {
|
415 |
+
clearTimeout(timeoutId);
|
416 |
console.error('Error setting up WebRTC:', err);
|
417 |
showError('Failed to establish connection. Please try again.');
|
418 |
stop();
|