aamirtaymoor commited on
Commit
8f76623
·
verified ·
1 Parent(s): 03c2a9c

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +16 -15
static/script.js CHANGED
@@ -1,26 +1,27 @@
1
  const textGenForm = document.querySelector('.text-gen-form');
2
 
3
  const translateText = async (text, rating) => {
4
- const inferResponse = await fetch(`predict`,
5
- {method: "POST",
6
- body: JSON.stringify({text:text, rating:rating}),
7
- headers: {"Content-type": "application/json; charset=UTF-8"}});
 
8
  const inferJson = await inferResponse.json();
9
 
10
  return inferJson.output;
11
  };
12
 
13
  textGenForm.addEventListener('submit', async (event) => {
14
- console.log("inside event listener")
15
- event.preventDefault();
16
 
17
- const textGenInput = document.getElementById('text-gen-input');
18
- const rating = document.getElementById('rating-input');
19
- const textGenParagraph = document.querySelector('.text-gen-output');
20
 
21
- try {
22
- textGenParagraph.textContent = await translateText(textGenInput.value, rating.value);
23
- } catch (err) {
24
- console.error(err);
25
- }
26
- });
 
 
1
  const textGenForm = document.querySelector('.text-gen-form');
2
 
3
  const translateText = async (text, rating) => {
4
+ const inferResponse = await fetch('/predict', {
5
+ method: "POST",
6
+ body: JSON.stringify({ text: text, rating: rating }),
7
+ headers: { "Content-type": "application/json; charset=UTF-8" }
8
+ });
9
  const inferJson = await inferResponse.json();
10
 
11
  return inferJson.output;
12
  };
13
 
14
  textGenForm.addEventListener('submit', async (event) => {
15
+ event.preventDefault();
 
16
 
17
+ const textGenInput = document.getElementById('text-gen-input').value;
18
+ const rating = document.getElementById('rating-input').value;
19
+ const textGenParagraph = document.querySelector('.text-gen-output');
20
 
21
+ try {
22
+ const output = await translateText(textGenInput, rating);
23
+ textGenParagraph.textContent = output;
24
+ } catch (err) {
25
+ console.error(err);
26
+ }
27
+ });