turner_ml / static /my_script.js
aamirtaymoor's picture
Update static/my_script.js
7323df1 verified
const textGenForm = document.querySelector('.text-gen-form');
const translateText = async (text, rating) => {
const inferResponse = await fetch(`predict`,
{method: "POST",
body: JSON.stringify({text:text, rating:rating}),
headers: {"Content-type": "application/json; charset=UTF-8"}});
const inferJson = await inferResponse.json();
const processed_data = inferJson.processed_data
const inferJsonStr = JSON.stringify(processed_data)
return inferJsonStr;
};
textGenForm.addEventListener('submit', async (event) => {
console.log("inside event listener")
event.preventDefault();
const textGenInput = document.getElementById('text-gen-input');
const rating = document.getElementById('rating-input');
const textGenParagraph = document.querySelector('.text-gen-output');
try {
const data = await translateText(textGenInput.value, rating.value)
textGenParagraph.textContent = data;
} catch (err) {
console.error(err);
}
});