Spaces:
Runtime error
Runtime error
| const generateButton = document.getElementById('generate'); | |
| generateButton.addEventListener('click', async () => { | |
| const accountSelect = document.getElementById('account'); | |
| const account = accountSelect.options[accountSelect.selectedIndex].value; | |
| const inputText = document.getElementById('input').value; | |
| const outputTextArea = document.getElementById('output'); | |
| outputTextArea.value = 'Loading and running model...'; | |
| try { | |
| const response = await fetch('/api/generate', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ account: account, text: inputText }) | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`Network response was not ok. Status: ${response.status} - ${response.statusText}`); | |
| } | |
| const data = await response.json(); | |
| const outputText = data.generated_text; | |
| document.getElementById('output').value = outputText; | |
| } catch (error) { | |
| console.error('Error:', error); | |
| outputTextArea.value = `Failed to fetch data. Reason: ${error.message}`; | |
| } | |
| }); |