lyimo commited on
Commit
e2d284e
·
verified ·
1 Parent(s): 84e51a1

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +22 -19
static/script.js CHANGED
@@ -1,21 +1,24 @@
1
- const textGenForm = document.querySelector('.text-gen-form');
 
 
 
 
 
2
 
3
- const translateText = async (text) => {
4
- const inferResponse = await fetch(`infer_t5?input=${text}`);
5
- const inferJson = await inferResponse.json();
6
 
7
- return inferJson.output;
8
- };
9
-
10
- textGenForm.addEventListener('submit', async (event) => {
11
- event.preventDefault();
12
-
13
- const textGenInput = document.getElementById('text-gen-input');
14
- const textGenParagraph = document.querySelector('.text-gen-output');
15
-
16
- try {
17
- textGenParagraph.textContent = await translateText(textGenInput.value);
18
- } catch (err) {
19
- console.error(err);
20
- }
21
- });
 
1
+ document.getElementById('submit-audio').addEventListener('click', async () => {
2
+ const audioInput = document.getElementById('audio-input');
3
+ if (audioInput.files.length === 0) {
4
+ alert('Please select an audio file.');
5
+ return;
6
+ }
7
 
8
+ const formData = new FormData();
9
+ formData.append('audio', audioInput.files[0]);
 
10
 
11
+ try {
12
+ const response = await fetch('/process_audio', {
13
+ method: 'POST',
14
+ body: formData
15
+ });
16
+ const data = await response.json();
17
+ document.querySelector('.response-text').textContent = data.response_text;
18
+ const audioElement = document.querySelector('.response-audio');
19
+ audioElement.src = data.response_audio_url;
20
+ audioElement.style.display = 'block';
21
+ } catch (error) {
22
+ console.error('Error:', error);
23
+ }
24
+ });