File size: 989 Bytes
02b4c7b
 
 
a2fd098
9dab54d
 
 
 
 
 
 
 
 
a2fd098
7c945fc
a2fd098
02b4c7b
 
 
 
 
 
 
 
 
83b990b
9df5fa1
ebb3e6c
301ea74
ae9ec04
220d69e
02b4c7b
 
 
3e57e69
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
const textGenForm = document.querySelector('.text-gen-form');

const translateText = async (text) => {
    const response = await fetch(
      `query_gorilla`,
      {
        method: 'POST',
        headers: {
          "Content-Type": "application/json",
        },
        body: text
      }
    );
    const responseJSON = await response.json();

    return JSON.stringify(responseJSON);
};

textGenForm.addEventListener('submit', async (event) => {
  event.preventDefault();

  const textGenInput = document.getElementById('text-gen-input');
  const textGenParagraph = document.querySelector('.text-gen-output');

  try {
    textGenParagraph.textContent = "Awaiting response ...";
    const start = Date.now()
    const txtResp = await translateText(textGenInput.value);
    console.info(txtResp);
    textGenParagraph.textContent = JSON.parse(txtResp).val[0]['generated_text'] + '\n\n' + 'Took ' + (Date.now() - start) + 'ms';
    
  } catch (err) {
    console.error(err);
  }
});