async function deleteRecord(clickedElement, type) { const recordElement = clickedElement.closest('.record'); makeLoading() if (recordElement) { const recordID = recordElement.getAttribute('record-id'); const response = await fetch('/delete-record', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({'record_id': parseInt(recordID), 'type': type}) }); if (response.ok) { stopLoading() recordElement.remove(); } } } async function getRecordTranscription(recordId, type) { try { makeLoading() const url = `/record/${recordId}/${type}/transcription`; const response = await fetch(url); if (!response.ok) { throw new Error(`Error: ${response.status}`); } const result = await response.json(); transcriptionReportBlock.innerHTML = marked.parse(result) stopLoading() } catch (error) { console.error('Failed to fetch transcription:', error); stopLoading() transcriptionReportBlock.innerText = ''; } } async function playRecord(recordId) { try { const url = `/record/${recordId}/audio/play`; makeLoading() const response = await fetch(url); if (!response.ok) { throw new Error(`Error: ${response.status}`); } const audioBase64 = await response.json(); const audioSrc = `data:audio/mp3;base64,${audioBase64}`; const audio = new Audio(audioSrc); stopLoading() await audio.play(); } catch (error) { stopLoading() console.error('Failed to fetch transcription:', error); } } async function createAIReport() { try { transcriptionReportBlock.innerText = '' const records = document.getElementsByClassName('record'); const imageRecordIDs = []; const audioRecordIDs = []; for (let i = 0; i < records.length; i++) { const recordID = records[i].getAttribute('record-id'); const objectType = records[i].getAttribute('object-type'); if (objectType === 'image') { imageRecordIDs.push(recordID); } else if (objectType === 'audio') { audioRecordIDs.push(recordID); } } if (imageRecordIDs.length === 0 && audioRecordIDs.length === 0) { alert('Record at least one audio or image.'); } const requestBody = JSON.stringify({ audio_ids: audioRecordIDs, image_ids: imageRecordIDs, language: selectLanguage.value }); makeLoading() const response = await fetch('/report', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: requestBody }); if (!response.ok) { const errorData = await response.json() throw new Error(errorData.detail); } const result = await response.json(); transcriptionReportBlock.innerHTML = marked.parse(result) stopLoading() } catch (error) { console.log(error) transcriptionReportBlock.innerHTML = `