File size: 4,790 Bytes
e3649b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3cd7383
e3649b7
 
376b0e4
e3649b7
 
1019ced
e3649b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Text Summarizer - BART Model</title>

    <!-- Bootstrap 4 CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css">

    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f8f9fa;
        }
        .navbar {
            background-color: #007bff;
        }
        .navbar-brand, .nav-link {
            color: white !important;
        }
        .hero-section {
            background: #007bff;
            color: white;
            padding: 60px 20px;
            text-align: center;
        }
        .content-section {
            padding: 40px 20px;
        }
        .summary-box {
            max-width: 600px;
            margin: auto;
            background: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body>

  
    <!-- Hero Section -->
    <div class="hero-section">
        <h1>AI-Powered Text Summarizer</h1>
        <p>Summarize long articles into concise and meaningful summaries using the BART model.</p>
    </div>


    <div class="container content-section">
        <h2 class="text-center mb-4">About the BART Model</h2>
        <p class="text-left">
            <strong>BART (Bidirectional and Auto-Regressive Transformer)</strong> is a sequence-to-sequence model that combines the strengths of both BERT and GPT. 
            It features a <strong>bidirectional encoder</strong>, similar to BERT, which understands context deeply, and an <strong>autoregressive decoder</strong>, like GPT, which generates text efficiently. 
        </p>
        <p class="text-left">
            Pre-trained using a <strong>denoising objective</strong>, BART reconstructs original text from corrupted input, making it highly effective for text generation tasks such as 
            <strong>summarization, translation, and question answering</strong>.
        </p>
    </div>

    <!-- Summarization Tool -->
    <div class="container content-section">
        <h2 class="text-center mb-4">Try the Summarizer</h2>
        <p class="text-center">Enter a passage, and the AI will generate a concise summary.</p>

        <div class="summary-box">
            <textarea id="userInput" class="form-control mb-3" rows="5" placeholder="Paste your text here..."></textarea>
            <button class="btn btn-primary btn-block" onclick="fetchSummary()">Summarize</button>
            <div class="spinner-border text-primary mt-3" id="loader" style="display:none;"></div>
            <div id="result" class="alert alert-secondary mt-3" style="display:none;"></div>
        </div>
    </div>

    <!-- Bootstrap 4 JS + jQuery -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

    <script>
      import fetch from "node-fetch";
        async function query(data) {
            const response = await fetch(
                "https://api-inference.huggingface.co/models/facebook/bart-large-cnn",
                {
                    headers: {
                        Authorization: "Bearer {HF_TOKEN}", // Replace with your actual token
                        "Content-Type": "application/json",
                    },
                    method: "POST",
                    body: JSON.stringify(data),
                }
            );
            const result = await response.json();
            return result;
        }

        async function fetchSummary() {
            const inputText = document.getElementById("userInput").value;
            const loader = document.getElementById("loader");
            const resultBox = document.getElementById("result");

            if (!inputText) {
                alert("Please enter some text.");
                return;
            }

            loader.style.display = "block";
            resultBox.style.display = "none";
            resultBox.innerText = "";

            try {
                const response = await query({ inputs: inputText });

                loader.style.display = "none";
                resultBox.style.display = "block";
                resultBox.innerHTML = `<strong>Summary:</strong> <br> ${response[0].summary_text}`;
            } catch (error) {
                loader.style.display = "none";
                alert("Error fetching summary. Please try again.");
            }
        }
    </script>

</body>
</html>