File size: 1,442 Bytes
ad02f33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { streamGemini } from './gemini-api.js';

let form = document.querySelector('form');
let output = document.querySelector('.output');
let audioFileInput = document.querySelector('input[name="audio_file"]');

form.onsubmit = async (ev) => {
  ev.preventDefault();
  output.textContent = 'Processing...';
  
  try {
    // Log form data before sending
    console.log('Preparing to send audio file:', audioFileInput.files[0]);

    // Create a FormData object to hold the audio file
    let formData = new FormData();
    formData.append('audio_file', audioFileInput.files[0]);

    // Send the audio file to the Flask backend for transcription and option selection
    let response = await fetch('/api/upload', {
      method: 'POST',
      body: formData
    });

    // Log the response status
    console.log('Response status:', response.status);

    if (!response.ok) {
      throw new Error('Network response was not ok');
    }

    let result = await response.json();
    let selectedOption = result.selected_option;

    // Log the response data
    console.log('Received result:', result);

    // Display the transcription and the selected option
    output.innerHTML = `

      <p>Transcription: ${result.transcription}</p>

      <p>Correct Option: ${selectedOption}</p>

    `;

  } catch (e) {
    console.error('Error occurred:', e);
    output.innerHTML = '<hr>' + e;
  }
};