Spaces:
Runtime error
Runtime error
// takes a text input and hit the endpoint with the text, then return the output | |
const textGenForm = document.querySelector('form'); | |
const translateText = async (text) => { | |
const inferResponse = await fetch(`prediction?input=${text}`); | |
const inferJson = await inferResponse.json(); | |
return inferJson.output; | |
}; | |
textGenForm.addEventListener('submit', async (event) => { | |
event.preventDefault(); | |
const textGenInput = document.getElementById('text-gen-input'); | |
const textGenParagraph = document.querySelector('.text-gen-output'); | |
try { | |
textGenParagraph.textContent = await translateText(textGenInput.value); | |
} catch (err) { | |
console.error(err); | |
} | |
}); |