Spaces:
Sleeping
Sleeping
File size: 7,685 Bytes
8fe50ee | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View Document - {{ filename }}</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">
<style>
.document-container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.document-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 1px solid #e5e7eb;
}
.back-button {
text-decoration: none;
color: #3b82f6;
display: flex;
align-items: center;
}
.back-button i {
margin-right: 5px;
}
.document-title {
margin: 0;
font-size: 1.5rem;
}
.document-actions {
display: flex;
gap: 10px;
}
.action-button {
background-color: #f3f4f6;
border: 1px solid #e5e7eb;
border-radius: 4px;
padding: 5px 10px;
cursor: pointer;
display: flex;
align-items: center;
transition: background-color 0.3s;
}
.action-button i {
margin-right: 5px;
}
.action-button:hover {
background-color: #e5e7eb;
}
.document-content {
background-color: #ffffff;
border: 1px solid #e5e7eb;
border-radius: 6px;
padding: 20px;
white-space: pre-wrap;
font-family: Arial, sans-serif;
line-height: 1.6;
max-height: 70vh;
overflow-y: auto;
}
.document-footer {
margin-top: 20px;
text-align: center;
font-size: 0.9rem;
color: #6b7280;
}
</style>
</head>
<body>
<div class="document-container">
<div class="document-header">
<a href="{{ url_for('home') }}" class="back-button">
<i class="fas fa-arrow-left"></i> Back to Home
</a>
<h1 class="document-title">{{ filename }}</h1>
<div class="document-actions">
<button class="action-button" id="generate-wordcloud-btn">
<i class="fas fa-cloud"></i> Generate Word Cloud
</button>
<button class="action-button" onclick="window.print()">
<i class="fas fa-print"></i> Print
</button>
</div>
</div>
<div class="document-content">
{{ content }}
</div>
<div id="wordcloud-container" style="display: none; margin-top: 20px;">
<h2><i class="fas fa-cloud"></i> Document Word Cloud</h2>
<div id="wordcloud-image-container" style="text-align: center; padding: 20px; background-color: #f9fafb; border-radius: 6px;">
<div id="loading-indicator" style="display: none;">
<i class="fas fa-spinner fa-spin"></i> Generating word cloud...
</div>
<img id="wordcloud-image" style="max-width: 100%; display: none;" />
</div>
<div id="word-frequency" style="margin-top: 15px; display: none;">
<h3>Word Frequency Statistics</h3>
<div id="word-frequency-list" style="display: flex; flex-wrap: wrap; gap: 10px;">
<!-- Word frequency data will be added here dynamically -->
</div>
</div>
</div>
<div class="document-footer">
<p>AI Teaching Assistant - Document Viewer</p>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const generateWordcloudBtn = document.getElementById('generate-wordcloud-btn');
const wordcloudContainer = document.getElementById('wordcloud-container');
const loadingIndicator = document.getElementById('loading-indicator');
const wordcloudImage = document.getElementById('wordcloud-image');
const wordFrequency = document.getElementById('word-frequency');
const wordFrequencyList = document.getElementById('word-frequency-list');
// If URL parameter generate_wordcloud=true, automatically generate word cloud
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('generate_wordcloud') === 'true') {
generateWordcloud();
}
generateWordcloudBtn.addEventListener('click', function() {
generateWordcloud();
});
function generateWordcloud() {
// Show word cloud container and loading indicator
wordcloudContainer.style.display = 'block';
loadingIndicator.style.display = 'block';
wordcloudImage.style.display = 'none';
wordFrequency.style.display = 'none';
// Get top_n parameter, default is 100
const topN = urlParams.get('top_n') || 100;
// Call word cloud API
fetch(`/api/wordcloud/{{ filename }}?top_n=${topN}`)
.then(response => {
if (!response.ok) {
throw new Error('Failed to generate word cloud');
}
return response.json();
})
.then(data => {
// Hide loading indicator
loadingIndicator.style.display = 'none';
// Show word cloud image - Fix field name to match backend
wordcloudImage.src = `data:image/png;base64,${data.wordcloud_image}`;
wordcloudImage.style.display = 'block';
// Show word frequency statistics
wordFrequency.style.display = 'block';
// Clear previous word frequency list
wordFrequencyList.innerHTML = '';
// Add word frequency data
data.word_frequency.forEach(([word, freq]) => {
const wordItem = document.createElement('div');
wordItem.className = 'word-item';
wordItem.style.padding = '5px 10px';
wordItem.style.backgroundColor = '#e5e7eb';
wordItem.style.borderRadius = '4px';
wordItem.innerHTML = `<strong>${word}</strong>: ${freq}`;
wordFrequencyList.appendChild(wordItem);
});
})
.catch(error => {
loadingIndicator.style.display = 'none';
wordFrequencyList.innerHTML = `<div style="color: red;">Error: ${error.message}</div>`;
});
}
});
</script>
</body>
</html> |