File size: 12,088 Bytes
634567d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3293ecf
 
 
 
 
 
 
634567d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3293ecf
 
 
 
634567d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3293ecf
 
 
634567d
 
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Single Summary - Smart Summarizer</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
    <!-- Top Navigation Bar -->
    <nav class="top-navbar">
        <a href="/" class="navbar-logo">
            <div class="logo-circle">S</div>
            <span>Smart Summarizer</span>
        </a>
        
        <!-- Mobile Menu Toggle -->
        <button class="mobile-menu-toggle" onclick="toggleMobileMenu()">
            <i class="fas fa-bars"></i>
        </button>
        
        <div class="navbar-links" id="navbarLinks">
            <a href="/" class="nav-item">
                <i class="fas fa-home"></i> Home
            </a>
            <a href="/single-summary" class="nav-item active">
                <i class="fas fa-file-alt"></i> Single Summary
            </a>
            <a href="/comparison" class="nav-item">
                <i class="fas fa-balance-scale"></i> Comparison
            </a>
            <a href="/batch" class="nav-item">
                <i class="fas fa-layer-group"></i> Batch
            </a>
            <a href="/evaluation" class="nav-item">
                <i class="fas fa-chart-bar"></i> Evaluation
            </a>
        </div>
    </nav>
                <i class="fas fa-chart-bar"></i> Evaluation
            </a>
        </div>
    </nav>

    <!-- Page Content -->
    <div class="page-container">
        <h1 class="page-title">Single Model Summary</h1>
        <p class="page-subtitle">Input your text and select a specialized model to begin.</p>
        
        <div class="content-grid">
            <!-- Input Section -->
            <div class="input-section">
                <div class="section-label">Input Text</div>
                
                <!-- Input Method Tabs -->
                <div class="input-tabs">
                    <button class="tab-btn active" onclick="switchTab('paste')">Paste Text</button>
                    <button class="tab-btn" onclick="switchTab('upload')">Upload File</button>
                </div>
                
                <!-- Paste Text Tab -->
                <div id="paste-tab" class="tab-content active">
                    <textarea 
                        class="text-input" 
                        id="inputText"
                        placeholder="Paste your source text here..."
                    ></textarea>
                    <div class="char-count">
                        <span id="charCount">0 characters</span>
                        <span id="wordCount">0 words</span>
                    </div>
                </div>
                
                <!-- Upload File Tab -->
                <div id="upload-tab" class="tab-content">
                    <div class="upload-area" id="uploadArea">
                        <div class="upload-icon">📄</div>
                        <p>Drag and drop a file here or click to browse</p>
                        <p class="upload-hint">Supported formats: .txt, .md, .pdf, .docx, .doc (Max 16MB)</p>
                        <input type="file" id="fileInput" accept=".txt,.md,.pdf,.docx,.doc" style="display: none;">
                    </div>
                    <div id="fileInfo" class="file-info" style="display: none;">
                        <span id="fileName"></span>
                        <button class="btn-remove" onclick="removeFile()">Remove</button>
                    </div>
                </div>
            </div>
            
            <!-- Output Section -->
            <div class="output-section">
                <div class="section-label">Output Preview</div>
                <div class="output-preview" id="outputPreview">
                    <div class="icon"></div>
                    <div>Summary will appear here</div>
                </div>
            </div>
        </div>
        
        <!-- Controls -->
        <div class="controls-section">
            <select class="model-select" id="modelSelect">
                <option value="bart">BART</option>
                <option value="textrank">TextRank</option>
                <option value="pegasus">PEGASUS</option>
            </select>
            
            <button class="btn-generate" id="generateBtn">
                Generate Summary
            </button>
        </div>
    </div>

    <!-- Footer -->
    <footer class="footer">
        <div class="footer-left">
            <div class="logo-circle" style="width: 24px; height: 24px; font-size: 0.9rem;">S</div>
            <span>Smart Summarizer</span>
        </div>
        <div class="footer-right">
            <span>© 2025 Smart Summarizer. Abdul Razzaq Ansari</span>
            <a href="https://github.com/Rajak13/Smart-Summarizer" target="_blank" class="footer-link">
                <i class="fab fa-github"></i> GitHub Repository
            </a>
        </div>
    </footer>

    <script>
        const inputText = document.getElementById('inputText');
        const charCount = document.getElementById('charCount');
        const wordCount = document.getElementById('wordCount');
        const generateBtn = document.getElementById('generateBtn');
        const modelSelect = document.getElementById('modelSelect');
        const outputPreview = document.getElementById('outputPreview');
        const fileInput = document.getElementById('fileInput');
        const uploadArea = document.getElementById('uploadArea');
        const fileInfo = document.getElementById('fileInfo');
        const fileName = document.getElementById('fileName');

        // Tab switching
        function switchTab(tab) {
            document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
            document.querySelectorAll('.tab-content').forEach(content => content.classList.remove('active'));
            
            if (tab === 'paste') {
                document.querySelector('.tab-btn:first-child').classList.add('active');
                document.getElementById('paste-tab').classList.add('active');
            } else {
                document.querySelector('.tab-btn:last-child').classList.add('active');
                document.getElementById('upload-tab').classList.add('active');
            }
        }

        // Update character and word count
        inputText.addEventListener('input', () => {
            const text = inputText.value;
            const chars = text.length;
            const words = text.trim().split(/\s+/).filter(word => word.length > 0).length;
            
            charCount.textContent = `${chars} characters`;
            wordCount.textContent = `${words} words`;
        });

        // File upload handling
        uploadArea.addEventListener('click', () => fileInput.click());
        
        uploadArea.addEventListener('dragover', (e) => {
            e.preventDefault();
            uploadArea.style.borderColor = 'var(--slate-blue)';
            uploadArea.style.background = 'rgba(109, 129, 150, 0.05)';
        });
        
        uploadArea.addEventListener('dragleave', () => {
            uploadArea.style.borderColor = 'var(--cool-gray)';
            uploadArea.style.background = 'transparent';
        });
        
        uploadArea.addEventListener('drop', async (e) => {
            e.preventDefault();
            uploadArea.style.borderColor = 'var(--cool-gray)';
            uploadArea.style.background = 'transparent';
            
            const file = e.dataTransfer.files[0];
            if (file) {
                await handleFileUpload(file);
            }
        });
        
        fileInput.addEventListener('change', async (e) => {
            const file = e.target.files[0];
            if (file) {
                await handleFileUpload(file);
            }
        });

        async function handleFileUpload(file) {
            const formData = new FormData();
            formData.append('file', file);
            
            try {
                const response = await fetch('/api/upload', {
                    method: 'POST',
                    body: formData
                });
                
                const data = await response.json();
                
                if (data.success) {
                    inputText.value = data.text;
                    inputText.dispatchEvent(new Event('input'));
                    
                    fileName.textContent = `${data.filename} (${data.word_count} words)`;
                    fileInfo.style.display = 'flex';
                    uploadArea.style.display = 'none';
                    
                    // Switch to paste tab to show the text
                    switchTab('paste');
                } else {
                    alert('Error: ' + data.error);
                }
            } catch (error) {
                alert('Failed to upload file. Please try again.');
                console.error(error);
            }
        }

        function removeFile() {
            fileInput.value = '';
            fileInfo.style.display = 'none';
            uploadArea.style.display = 'flex';
            inputText.value = '';
            inputText.dispatchEvent(new Event('input'));
        }

        // Generate summary
        generateBtn.addEventListener('click', async () => {
            const text = inputText.value.trim();
            const model = modelSelect.value;
            
            if (!text || text.split(/\s+/).length < 10) {
                alert('Please enter at least 10 words of text');
                return;
            }
            
            // Show loading state
            generateBtn.disabled = true;
            generateBtn.textContent = 'Generating...';
            outputPreview.innerHTML = '<div class="spinner"></div><div>Processing your text...</div>';
            
            try {
                const response = await fetch('/api/summarize', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        text: text,
                        model: model
                    })
                });
                
                const data = await response.json();
                
                if (data.success) {
                    // Display summary
                    outputPreview.innerHTML = `
                        <div class="output-text">
                            <strong>Summary (${model.toUpperCase()}):</strong><br><br>
                            ${data.summary}
                            <br><br>
                            <small style="color: var(--slate-blue);">
                                Processing time: ${data.metadata.processing_time.toFixed(2)}s | 
                                Compression: ${(data.metadata.compression_ratio * 100).toFixed(1)}%
                            </small>
                        </div>
                    `;
                } else {
                    outputPreview.innerHTML = `
                        <div style="color: #ef4444;">
                            <strong>Error:</strong> ${data.error}
                        </div>
                    `;
                }
            } catch (error) {
                outputPreview.innerHTML = `
                    <div style="color: #ef4444;">
                        <strong>Error:</strong> Failed to generate summary. Please try again.
                    </div>
                `;
            } finally {
                generateBtn.disabled = false;
                generateBtn.textContent = 'Generate Summary';
            }
        });
    </script>
    
    <!-- Mobile Menu JavaScript -->
    <script src="{{ url_for('static', filename='js/mobile-menu.js') }}"></script>
</body>
</html>