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); } });