yahiadevs's picture
Upload 3 files
51bfe5f verified
async function summarizeText() {
const inputText = document.getElementById('inputText').value;
const summaryDiv = document.getElementById('summary');
summaryDiv.innerHTML = "<em>Summarizing... Please wait.</em>";
// Now call YOUR backend endpoint, not Hugging Face's directly
const response = await fetch("http://localhost:5000/summarize", { // Your server's address
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ text: inputText }), // Send data to your server
});
const result = await response.json();
// Display the result
if (result.error) {
// Handle errors (e.g., model is loading)
summaryDiv.innerHTML = `<strong>Error:</strong> ${result.error}`;
} else if (result[0] && result[0].summary_text) {
// Display the summary
summaryDiv.innerHTML = `<strong>Summary:</strong> ${result[0].summary_text}`;
} else {
summaryDiv.innerHTML = "<em>Unexpected response from API.</em>";
}
}