Public
Edited
Nov 4, 2024
Insert cell
Insert cell
Insert cell
Insert cell
fetch('https://python-in-a-flask.glitch.me')
.then(response => response.json())
.then(d => d.message)
Insert cell
fetch("https://python-in-a-flask.glitch.me/version")
.then(response => response.json())
.then(d => d.python_version)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// URL of your Flask app's predict endpoint
predictUrl = "https://python-in-a-flask.glitch.me/predict";
Insert cell
theta_best = trainResponse.theta
Insert cell
// Function to send the POST request for training
trainResponse = fetch(trainUrl, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(trainData)
})
.then(response => response.json())
.then(data => {
if (data.error) {
throw new Error(data.error);
}
return data;
})
.catch(error => {
console.error("Error training model:", error);
return { error: error.message };
});
Insert cell
// Function to send the POST request for prediction
predictResponse = {
// Data to send in the request
const predictData = {
features: [1.5] // Example feature data
};

const predictResponse = fetch(predictUrl, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(predictData)
})
.then(response => response.json())
.then(data => {
if (data.error) {
throw new Error(data.error);
}
return data;
})
.catch(error => {
console.error("Error fetching prediction:", error);
return { error: error.message };
});

return predictResponse;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more