File size: 1,084 Bytes
3302982
 
eb48ea5
50ac9b8
 
 
 
3302982
e5180db
 
43c9d6a
3302982
 
 
50ac9b8
 
3302982
50ac9b8
 
 
3302982
50ac9b8
88b5803
 
50ac9b8
 
 
 
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
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);
  }
});