File size: 1,281 Bytes
779624b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
document.addEventListener('DOMContentLoaded', () => {
    const form = document.querySelector('.text-gen-form');
    const input = document.getElementById('text-gen-input');
    const output = document.querySelector('.text-gen-output');
  
    form.addEventListener('submit', async (e) => {
      e.preventDefault();
  
      const textPrompt = input.value.trim();
  
      if (textPrompt) {
        try {
          const response = await fetch('/sepsis/predict', {
            method: 'GET',
            headers: {
              'Content-Type': 'application/json',
            },
            body: JSON.stringify({ textPrompt }),
          });
  
          const data = await response.json();
  
          if (response.ok) {
            const { predicted_sepsis, statement, user_input_statement } = data;
  
            // Update the output element with the predicted sepsis status and statement
            output.textContent = `${user_input_statement}\n\n${statement}`;
          } else {
            output.textContent = 'Error: Unable to fetch prediction.';
          }
        } catch (error) {
          output.textContent = 'Error: Something went wrong.';
        }
      } else {
        output.textContent = 'Error: Text prompt cannot be empty.';
      }
    });
  });