Dreamy0 commited on
Commit
722315c
·
verified ·
1 Parent(s): 9fc7bff

Update ui/script.js

Browse files
Files changed (1) hide show
  1. ui/script.js +36 -30
ui/script.js CHANGED
@@ -1,30 +1,36 @@
1
- async function analyze() {
2
- const text = document.getElementById('textInput').value;
3
- const output = document.getElementById('output');
4
- const label = document.getElementById('label');
5
- const confidence = document.getElementById('confidence');
6
- const roast = document.getElementById('roast');
7
-
8
- output.style.display = 'none';
9
- label.textContent = '';
10
- confidence.textContent = '';
11
- roast.textContent = '';
12
-
13
- try {
14
- const response = await fetch(window.location.origin + `/predict`, {
15
- method: 'POST',
16
- headers: { 'Content-Type': 'application/json' },
17
- body: JSON.stringify({ text })
18
- });
19
-
20
- const data = await response.json();
21
- label.textContent = data.label;
22
- confidence.textContent = (data.confidence * 100).toFixed(2);
23
- roast.textContent = data.roast;
24
- output.style.display = 'block';
25
- } catch (err) {
26
- console.error(err);
27
- roast.textContent = "Something went wrong. EmoNet had a breakdown.";
28
- output.style.display = 'block';
29
- }
30
- }
 
 
 
 
 
 
 
1
+ async function analyze() {
2
+ const text = document.getElementById('textInput').value;
3
+ const output = document.getElementById('output');
4
+ const label = document.getElementById('label');
5
+ const confidence = document.getElementById('confidence');
6
+ const roast = document.getElementById('roast');
7
+
8
+ output.style.display = 'none';
9
+ label.textContent = '';
10
+ confidence.textContent = '';
11
+ roast.textContent = '';
12
+
13
+ // 👇 YOUR NGROK URL GOES HERE
14
+ const API_URL = "https://c179cffb5e08.ngrok-free.app";
15
+
16
+ try {
17
+ const response = await fetch(`${API_URL}/predict`, {
18
+ method: 'POST',
19
+ headers: { 'Content-Type': 'application/json' },
20
+ body: JSON.stringify({ text })
21
+ });
22
+
23
+ const data = await response.json();
24
+
25
+ label.textContent = data.label;
26
+ confidence.textContent = (data.confidence * 100).toFixed(2);
27
+ roast.textContent = data.roast;
28
+
29
+ output.style.display = 'block';
30
+
31
+ } catch (err) {
32
+ console.error(err);
33
+ roast.textContent = "Something went wrong. EmoNet had a breakdown.";
34
+ output.style.display = 'block';
35
+ }
36
+ }