edit in the curriculum_PDF_uploader.html

parent ae47fc46
...@@ -105,22 +105,22 @@ ...@@ -105,22 +105,22 @@
<pre id="response" style="display:none;"></pre> <pre id="response" style="display:none;"></pre>
</div> </div>
<script> <script>
const API_URL = 'http://localhost:8000/process-curriculum'; // The API_URL constant is no longer needed and has been removed.
const pdfFileInput = document.getElementById('pdfFile'); const pdfFileInput = document.getElementById('pdfFile');
const uploadButton = document.getElementById('uploadButton'); const uploadButton = document.getElementById('uploadButton');
const statusDiv = document.getElementById('status'); const statusDiv = document.getElementById('status');
const responsePre = document.getElementById('response'); const responsePre = document.getElementById('response');
const gradeInput = document.getElementById('gradeInput'); const gradeInput = document.getElementById('gradeInput');
const subjectInput = document.getElementById('subjectInput'); // <-- Get the new subject field const subjectInput = document.getElementById('subjectInput');
uploadButton.addEventListener('click', async () => { uploadButton.addEventListener('click', async () => {
const selectedFile = pdfFileInput.files[0]; const selectedFile = pdfFileInput.files[0];
const grade = gradeInput.value; const grade = gradeInput.value;
const subject = subjectInput.value; // <-- Get the subject value const subject = subjectInput.value;
// --- Update validation ---
if (!selectedFile) { showStatus('Please select a PDF file first.', 'error'); return; } if (!selectedFile) { showStatus('Please select a PDF file first.', 'error'); return; }
if (!grade) { showStatus('Please enter a grade.', 'error'); return; } if (!grade) { showStatus('Please enter a grade.', 'error'); return; }
if (!subject) { showStatus('Please enter a subject.', 'error'); return; } if (!subject) { showStatus('Please enter a subject.', 'error'); return; }
...@@ -130,21 +130,21 @@ ...@@ -130,21 +130,21 @@
formData.append('grade', grade); formData.append('grade', grade);
formData.append('subject', subject); formData.append('subject', subject);
// 3. Update UI to show processing state
showStatus('Uploading and starting background processing...', 'processing'); showStatus('Uploading and starting background processing...', 'processing');
uploadButton.disabled = true; uploadButton.disabled = true;
responsePre.style.display = 'none'; responsePre.style.display = 'none';
try { try {
// 4. Send the file AND grade to the API // --- THIS IS THE FIX ---
const response = await fetch(API_URL, { // We now `await` the fetch call and assign its result to `response`.
const response = await fetch('/process-curriculum', {
method: 'POST', method: 'POST',
body: formData, body: formData,
}); });
// This line can now work correctly because the 'response' variable exists.
const responseData = await response.json(); const responseData = await response.json();
// 5. Handle the server's response
if (!response.ok) { if (!response.ok) {
throw new Error(responseData.detail || `Server error: ${response.statusText}`); throw new Error(responseData.detail || `Server error: ${response.statusText}`);
} }
...@@ -154,9 +154,9 @@ ...@@ -154,9 +154,9 @@
responsePre.style.display = 'block'; responsePre.style.display = 'block';
} catch (error) { } catch (error) {
// Network errors or other exceptions will be caught here.
showStatus(`An error occurred: ${error.message}`, 'error'); showStatus(`An error occurred: ${error.message}`, 'error');
} finally { } finally {
// 6. Re-enable the button
uploadButton.disabled = false; uploadButton.disabled = false;
} }
}); });
...@@ -167,6 +167,8 @@ ...@@ -167,6 +167,8 @@
statusDiv.className = `status ${type}`; statusDiv.className = `status ${type}`;
statusDiv.style.display = 'block'; statusDiv.style.display = 'block';
} }
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment