File size: 6,779 Bytes
cf1fb4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3cc77a
 
 
 
 
 
 
cf1fb4e
c3cc77a
cf1fb4e
c3cc77a
cf1fb4e
 
c3cc77a
cf1fb4e
c3cc77a
d0c2354
c3cc77a
 
 
cf1fb4e
2f03540
c3cc77a
 
 
 
cf1fb4e
 
c3cc77a
cf1fb4e
 
c3cc77a
 
cf1fb4e
 
 
 
 
 
c3cc77a
cf1fb4e
 
 
 
 
c3cc77a
cf1fb4e
 
c3cc77a
cf1fb4e
 
d0c2354
 
 
 
 
 
 
 
 
 
 
 
 
c3cc77a
2f03540
c3cc77a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf1fb4e
 
 
c3cc77a
cf1fb4e
 
d0c2354
cf1fb4e
 
 
 
 
 
c3cc77a
 
 
2f03540
c3cc77a
2f03540
 
 
 
 
 
 
 
c3cc77a
d0c2354
c3cc77a
 
d0c2354
c3cc77a
 
cf1fb4e
 
 
d0c2354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf1fb4e
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>News Feed Hub</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f4f4f9;
            color: #333;
        }
        h1 {
            text-align: center;
            color: #2c3e50;
        }
        .search-container {
            text-align: center;
            margin: 20px 0;
        }
        .search-bar {
            width: 50%;
            padding: 12px;
            font-size: 16px;
            border: 2px solid #3498db;
            border-radius: 25px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
            outline: none;
            transition: border-color 0.3s;
        }
        .search-bar:focus {
            border-color: #2980b9;
        }
        .category-section {
            margin: 30px 0;
        }
        .category-title {
            background-color: #3498db;
            color: white;
            padding: 10px;
            border-radius: 5px;
            font-size: 1.4em;
            text-align: center;
        }
        .tiles {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
            justify-content: center;
        }
        .article-tile {
            background-color: white;
            width: 300px;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            transition: transform 0.2s;
            overflow: hidden;
            position: relative;
        }
        .article-tile:hover {
            transform: scale(1.05);
        }
        .article-tile img, .article-tile svg {
            width: 100%;
            height: 150px;
            object-fit: cover;
            border-radius: 5px;
        }
        .title a {
            font-size: 1.1em;
            color: #2c3e50;
            text-decoration: none;
            display: block;
            margin: 10px 0;
        }
        .title a:hover {
            color: #3498db;
        }
        .summary {
            color: #555;
            font-size: 0.9em;
            margin: 5px 0;
        }
        .sentiment {
            font-style: italic;
            color: #7f8c8d;
            font-size: 0.85em;
        }
        .published {
            font-size: 0.8em;
            color: #95a5a6;
        }
        .summarize-btn {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 5px 10px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 0.8em;
            margin-top: 10px;
        }
        .summarize-btn:hover {
            background-color: #2980b9;
        }
        #loading {
            display: block;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            z-index: 1000;
        }
        .loader {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 50px;
            height: 50px;
            border: 5px solid #f3f3f3;
            border-top: 5px solid #3498db;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            0% { transform: translate(-50%, -50%) rotate(0deg); }
            100% { transform: translate(-50%, -50%) rotate(360deg); }
        }
    </style>
</head>
<body>
    <div id="loading"><div class="loader"></div></div>
    <h1>News Feed Hub</h1>
    <div class="search-container">
        <form method="POST" id="searchForm">
            <input type="text" name="search" class="search-bar" placeholder="Search news semantically...">
        </form>
    </div>
    {% for category, articles in categorized_articles.items() %}
    <div class="category-section">
        <div class="category-title">{{ category }}</div>
        <div class="tiles">
            {% for article in articles %}
            <div class="article-tile">
                {% if article.image != "svg" %}
                <img src="{{ article.image }}" alt="Article Image">
                {% else %}
                <svg width="100%" height="150" viewBox="0 0 300 150" xmlns="http://www.w3.org/2000/svg">
                    <rect width="300" height="150" fill="#e0e0e0"/>
                    <text x="50%" y="50%" text-anchor="middle" dy=".3em" font-size="20" fill="#666">
                        No Image Available
                    </text>
                </svg>
                {% endif %}
                <div class="title"><a href="{{ article.link }}" target="_blank">{{ article.title }}</a></div>
                <div class="summary" id="summary-{{ loop.index }}-{{ category|replace(' ', '-') }}">{{ article.summary }}</div>
                <div class="sentiment">Sentiment: {{ article.sentiment }}</div>
                <div class="published">Published: {{ article.published }}</div>
                <button class="summarize-btn" onclick="summarizeArticle('{{ article.original_description|escapejs }}', 'summary-{{ loop.index }}-{{ category|replace(' ', '-') }}')">Summarize</button>
            </div>
            {% endfor %}
        </div>
    </div>
    {% endfor %}

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const form = document.getElementById('searchForm');
            const loading = document.getElementById('loading');
            
            form.addEventListener('submit', () => {
                loading.style.display = 'block';
            });

            window.addEventListener('load', () => {
                loading.style.display = 'none';
            });
        });

        function summarizeArticle(text, summaryId) {
            const loading = document.getElementById('loading');
            loading.style.display = 'block';
            fetch('/summarize', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ text: text }),
            })
            .then(response => response.json())
            .then(data => {
                document.getElementById(summaryId).innerText = data.summary;
                loading.style.display = 'none';
            })
            .catch(error => {
                console.error('Error:', error);
                document.getElementById(summaryId).innerText = 'Error summarizing';
                loading.style.display = 'none';
            });
        }
    </script>
</body>
</html>