var topicForm = document.getElementById('topic-form'); if (topicForm) { topicForm.addEventListener('submit', function(event) { event.preventDefault(); var topic = document.getElementById('topic').value; fetch('/generate-section', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'topic=' + encodeURIComponent(topic) }) .then(response => response.json()) .then(data => { var output = document.getElementById('output'); if (data.error) { output.textContent = data.error; } else { output.innerHTML = 'Your Question:
' + topic + '

Genie Says:
' + data.section + '
Cosine Similarity:
' + data.cosine_similarity.toFixed(2) } // Show the output div after getting the response output.style.display = 'block'; }); }); } function submitChatForm(event) { event.preventDefault(); var message = document.getElementById('message').value; console.log('Submitting message:', message); // Add this line for debugging fetch('/chat', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'message=' + encodeURIComponent(message) }) .then(response => { console.log('Response received:', response); // Add this line for debugging return response.json(); }) .then(data => { console.log('Data received:', data); // Add this line for debugging var chatContainer = document.getElementById('chat-output'); if (data.error) { chatContainer.innerHTML += '

' + data.error + '

'; } else { chatContainer.innerHTML += '

Your Query:

' + message + '\n'; // Add newline character here chatContainer.innerHTML += '

Genie Says:

' + data.model_response + '\n'; // Add newline character here } chatContainer.scrollTop = chatContainer.scrollHeight; }); } function saveChat() { const chatContent = document.getElementById('chat-output').textContent; const blob = new Blob([chatContent], { type: "text/plain;charset=utf-8" }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = 'chat-session.txt'; link.click(); } document.getElementById('save-button').addEventListener('click', saveChat); var clearDocument = document.getElementById('clear-document-btn'); if (clearDocument) { clearDocument.addEventListener('click', function(event) { event.preventDefault(); fetch('/clear-document', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'clear_output=true' }) .then(response => response.text()) .then(data => { var output = document.getElementById('output'); output.textContent = ''; // Clear the output section // Hide the output div after clearing the output output.style.display = 'none'; }); }); }