Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- 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(
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
const inferJson = await inferResponse.json();
|
| 9 |
|
| 10 |
return inferJson.output;
|
| 11 |
};
|
| 12 |
|
| 13 |
textGenForm.addEventListener('submit', async (event) => {
|
| 14 |
-
|
| 15 |
-
event.preventDefault();
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 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 |
+
});
|