Spaces:
Runtime error
Runtime error
Commit
·
acf96b5
1
Parent(s):
718a316
Update static/main.js
Browse files- static/main.js +18 -10
static/main.js
CHANGED
@@ -1,28 +1,36 @@
|
|
1 |
-
|
2 |
const generateButton = document.getElementById('generate');
|
3 |
-
//console.log("Hello, world!");
|
4 |
generateButton.addEventListener('click', async () => {
|
5 |
const accountSelect = document.getElementById('account');
|
6 |
const account = accountSelect.options[accountSelect.selectedIndex].value;
|
7 |
const inputText = document.getElementById('input').value;
|
8 |
|
9 |
const outputTextArea = document.getElementById('output');
|
10 |
-
outputTextArea.value = 'Loading
|
11 |
-
|
12 |
|
13 |
try {
|
14 |
const response = await fetch('/api/generate', {
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
19 |
if (!response.ok) {
|
20 |
throw new Error(`Network response was not ok. Status: ${response.status} - ${response.statusText}`);
|
21 |
}
|
22 |
-
|
|
|
|
|
23 |
|
|
|
24 |
const outputText = data.generated_text;
|
25 |
-
|
|
|
|
|
26 |
} catch (error) {
|
27 |
console.error('Error:', error);
|
28 |
outputTextArea.value = `Failed to fetch data. Reason: ${error.message}`;
|
|
|
|
|
1 |
const generateButton = document.getElementById('generate');
|
2 |
+
// console.log("Hello, world!");
|
3 |
generateButton.addEventListener('click', async () => {
|
4 |
const accountSelect = document.getElementById('account');
|
5 |
const account = accountSelect.options[accountSelect.selectedIndex].value;
|
6 |
const inputText = document.getElementById('input').value;
|
7 |
|
8 |
const outputTextArea = document.getElementById('output');
|
9 |
+
outputTextArea.value = 'Loading...';
|
|
|
10 |
|
11 |
try {
|
12 |
const response = await fetch('/api/generate', {
|
13 |
+
method: 'POST',
|
14 |
+
headers: { 'Content-Type': 'application/json' },
|
15 |
+
body: JSON.stringify({ account: account, text: inputText })
|
16 |
+
});
|
17 |
+
|
18 |
+
if (response.ok){
|
19 |
+
outputTextArea.value = 'Generating a reply...';
|
20 |
+
}
|
21 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
22 |
if (!response.ok) {
|
23 |
throw new Error(`Network response was not ok. Status: ${response.status} - ${response.statusText}`);
|
24 |
}
|
25 |
+
|
26 |
+
// First step update: POST request successful
|
27 |
+
outputTextArea.value = 'Model is running...';
|
28 |
|
29 |
+
const data = await response.json();
|
30 |
const outputText = data.generated_text;
|
31 |
+
|
32 |
+
// Second step update: Model completed running
|
33 |
+
outputTextArea.value = outputText;
|
34 |
} catch (error) {
|
35 |
console.error('Error:', error);
|
36 |
outputTextArea.value = `Failed to fetch data. Reason: ${error.message}`;
|