|
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; |
|
|
|
|
|
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.'; |
|
} |
|
}); |
|
}); |
|
|