-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
64 lines (48 loc) · 2.05 KB
/
script.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// script.js
function toggleSidebar() {
const sidebar = document.querySelector('.sidebar');
sidebar.classList.toggle('active'); // Toggle sidebar visibility
// Adjust main content based on sidebar state
const mainContent = document.querySelector('main');
if (sidebar.classList.contains('active')) {
mainContent.style.width = 'calc(100% - 250px)'; // Reduce width for sidebar
} else {
mainContent.style.width = '100%'; // Full width when sidebar is hidden
}
}
document.getElementById('prediction-form').addEventListener('submit', async function(event) {
event.preventDefault(); // Prevent page refresh on form submit
// Get the input data from the form
const inputData = document.getElementById('inputData').value;
try {
// Make the API call to get the prediction
const response = await fetch('http://your-api-url.com/predict', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
data: inputData, // The data being sent to the API
}),
});
// Check if the response is OK
if (!response.ok) {
throw new Error('Error in API call');
}
// Parse the response JSON
const result = await response.json();
// Display the result on the webpage
document.getElementById('prediction-result').innerText = `Prediction: ${result.prediction}`;
} catch (error) {
console.error('Error:', error);
document.getElementById('prediction-result').innerText = 'Error in fetching prediction';
}
});
// Example of updating the prediction result dynamically
function displayPredictionResult(result) {
const predictionBox = document.getElementById('prediction-result');
predictionBox.innerHTML = `<p>${result}</p>`;
predictionBox.style.display = 'block'; // Show the result box when there's a result
}
// Example usage
displayPredictionResult('The predicted network performance is 85% accuracy.');