Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +18 -1
static/script.js
CHANGED
@@ -47,4 +47,21 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
47 |
|
48 |
// Attempt to connect to the endpoint
|
49 |
initConnection();
|
50 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
// Attempt to connect to the endpoint
|
49 |
initConnection();
|
50 |
+
});
|
51 |
+
const textGenForm = document.querySelector(".text-gen-form");
|
52 |
+
|
53 |
+
const translateText = async (text) => {
|
54 |
+
const inferResponse = await fetch(`/infer_t5?input=${encodeURIComponent(text)}`);
|
55 |
+
const inferJson = await inferResponse.json();
|
56 |
+
|
57 |
+
return inferJson.output;
|
58 |
+
};
|
59 |
+
|
60 |
+
textGenForm.addEventListener("submit", async (event) => {
|
61 |
+
event.preventDefault();
|
62 |
+
|
63 |
+
const textGenInput = document.getElementById("text-gen-input");
|
64 |
+
const textGenParagraph = document.querySelector(".text-gen-output");
|
65 |
+
|
66 |
+
textGenParagraph.textContent = await translateText(textGenInput.value);
|
67 |
+
});
|