Spaces:
Running
Running
Update index.html
Browse files- index.html +62 -0
index.html
CHANGED
@@ -231,6 +231,68 @@
|
|
231 |
// Don't request permission automatically - wait for user to click button
|
232 |
displayStatus('Ready - Click "Start Listening" to begin');
|
233 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
</script>
|
235 |
</body>
|
236 |
</html>
|
|
|
231 |
// Don't request permission automatically - wait for user to click button
|
232 |
displayStatus('Ready - Click "Start Listening" to begin');
|
233 |
};
|
234 |
+
function processFinalTranscript(transcript) {
|
235 |
+
if (!transcript || transcript === 'Listening...') return;
|
236 |
+
|
237 |
+
console.log('Processing final transcript:', transcript);
|
238 |
+
|
239 |
+
// Show thinking animation while processing
|
240 |
+
setEmotion('thinking');
|
241 |
+
transcriptText.textContent = 'Processing...';
|
242 |
+
|
243 |
+
// Send the transcript to the API
|
244 |
+
query({ question: transcript })
|
245 |
+
.then(response => {
|
246 |
+
console.log('API response:', response);
|
247 |
+
|
248 |
+
// Display the response
|
249 |
+
transcriptText.textContent = response.text;
|
250 |
+
|
251 |
+
// Set back to default emotion
|
252 |
+
setEmotion('default');
|
253 |
+
|
254 |
+
// Clear transcript after a delay
|
255 |
+
setTimeout(() => {
|
256 |
+
if (!isListening) {
|
257 |
+
transcriptContainer.style.opacity = '0';
|
258 |
+
setTimeout(() => {
|
259 |
+
transcriptText.textContent = '';
|
260 |
+
}, 300);
|
261 |
+
}
|
262 |
+
}, 5000);
|
263 |
+
})
|
264 |
+
.catch(error => {
|
265 |
+
console.error('API error:', error);
|
266 |
+
transcriptText.textContent = 'Sorry, there was an error processing your request.';
|
267 |
+
setEmotion('default');
|
268 |
+
});
|
269 |
+
}
|
270 |
+
|
271 |
+
// API query function
|
272 |
+
async function query(data) {
|
273 |
+
try {
|
274 |
+
const response = await fetch(
|
275 |
+
"https://srivatsavdamaraju-flowise.hf.space/api/v1/prediction/2875301a-c26f-4bd5-ab10-71fa13393541",
|
276 |
+
{
|
277 |
+
method: "POST",
|
278 |
+
headers: {
|
279 |
+
"Content-Type": "application/json"
|
280 |
+
},
|
281 |
+
body: JSON.stringify(data)
|
282 |
+
}
|
283 |
+
);
|
284 |
+
|
285 |
+
if (!response.ok) {
|
286 |
+
throw new Error(`API responded with status: ${response.status}`);
|
287 |
+
}
|
288 |
+
|
289 |
+
const result = await response.json();
|
290 |
+
return result;
|
291 |
+
} catch (error) {
|
292 |
+
console.error('API query error:', error);
|
293 |
+
throw error;
|
294 |
+
}
|
295 |
+
}
|
296 |
</script>
|
297 |
</body>
|
298 |
</html>
|