File size: 1,158 Bytes
51bfe5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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>";
            }
}