Abubakari commited on
Commit
1ef167e
1 Parent(s): 779624b
Files changed (1) hide show
  1. static/script.js +14 -30
static/script.js CHANGED
@@ -1,38 +1,22 @@
1
  document.addEventListener('DOMContentLoaded', () => {
2
- const form = document.querySelector('.text-gen-form');
3
- const input = document.getElementById('text-gen-input');
4
- const output = document.querySelector('.text-gen-output');
5
 
6
- form.addEventListener('submit', async (e) => {
7
- e.preventDefault();
8
 
9
- const textPrompt = input.value.trim();
 
 
10
 
11
- if (textPrompt) {
12
- try {
13
- const response = await fetch('/sepsis/predict', {
14
- method: 'GET',
15
- headers: {
16
- 'Content-Type': 'application/json',
17
- },
18
- body: JSON.stringify({ textPrompt }),
19
- });
20
 
21
- const data = await response.json();
22
-
23
- if (response.ok) {
24
- const { predicted_sepsis, statement, user_input_statement } = data;
25
-
26
- // Update the output element with the predicted sepsis status and statement
27
- output.textContent = `${user_input_statement}\n\n${statement}`;
28
- } else {
29
- output.textContent = 'Error: Unable to fetch prediction.';
30
- }
31
- } catch (error) {
32
- output.textContent = 'Error: Something went wrong.';
33
- }
34
- } else {
35
- output.textContent = 'Error: Text prompt cannot be empty.';
36
  }
37
  });
38
  });
 
1
  document.addEventListener('DOMContentLoaded', () => {
2
+ const form = document.querySelector('#sepsis-prediction form');
3
+ const result = document.querySelector('#sepsis-result');
 
4
 
5
+ form.addEventListener('submit', async (event) => {
6
+ event.preventDefault();
7
 
8
+ const formData = new FormData(form);
9
+ const urlParams = new URLSearchParams(formData);
10
+ const url = `/sepsis/predict?${urlParams.toString()}`;
11
 
12
+ try {
13
+ const response = await fetch(url);
14
+ const data = await response.json();
 
 
 
 
 
 
15
 
16
+ result.textContent = data.statement;
17
+ } catch (error) {
18
+ console.error('Error:', error);
19
+ result.textContent = 'An error occurred while processing the request.';
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
  });
22
  });