| <!DOCTYPE html>
|
| <html lang="en">
|
| <head>
|
| <meta charset="UTF-8">
|
| <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| <title>AI Book Extraction System</title>
|
| <style>
|
| * {
|
| margin: 0;
|
| padding: 0;
|
| box-sizing: border-box;
|
| }
|
|
|
| body {
|
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| min-height: 100vh;
|
| padding: 20px;
|
| }
|
|
|
| .container {
|
| max-width: 800px;
|
| margin: 0 auto;
|
| }
|
|
|
| .header {
|
| background: white;
|
| padding: 30px;
|
| border-radius: 15px;
|
| box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
| text-align: center;
|
| margin-bottom: 30px;
|
| }
|
|
|
| .header h1 {
|
| color: #667eea;
|
| font-size: 2.5em;
|
| margin-bottom: 10px;
|
| }
|
|
|
| .header p {
|
| color: #666;
|
| font-size: 1.1em;
|
| }
|
|
|
| .reconnect-banner {
|
| background: #ff9800;
|
| color: white;
|
| padding: 15px;
|
| border-radius: 10px;
|
| margin-bottom: 20px;
|
| text-align: center;
|
| font-weight: 600;
|
| display: none;
|
| }
|
|
|
| .reconnect-banner.show {
|
| display: block;
|
| }
|
|
|
| .card {
|
| background: white;
|
| padding: 30px;
|
| border-radius: 15px;
|
| box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
| margin-bottom: 20px;
|
| }
|
|
|
| .input-group {
|
| margin-bottom: 20px;
|
| }
|
|
|
| .input-group label {
|
| display: block;
|
| margin-bottom: 10px;
|
| color: #333;
|
| font-weight: 600;
|
| font-size: 1.1em;
|
| }
|
|
|
| .input-group input {
|
| width: 100%;
|
| padding: 15px;
|
| border: 2px solid #e0e0e0;
|
| border-radius: 8px;
|
| font-size: 1em;
|
| transition: border-color 0.3s;
|
| }
|
|
|
| .input-group input:focus {
|
| outline: none;
|
| border-color: #667eea;
|
| }
|
|
|
| .btn {
|
| width: 100%;
|
| padding: 15px;
|
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| color: white;
|
| border: none;
|
| border-radius: 8px;
|
| font-size: 1.2em;
|
| font-weight: 600;
|
| cursor: pointer;
|
| transition: transform 0.2s, box-shadow 0.2s;
|
| }
|
|
|
| .btn:hover {
|
| transform: translateY(-2px);
|
| box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
|
| }
|
|
|
| .btn:active {
|
| transform: translateY(0);
|
| }
|
|
|
| .btn:disabled {
|
| background: #ccc;
|
| cursor: not-allowed;
|
| transform: none;
|
| }
|
|
|
| .progress-card {
|
| display: none;
|
| }
|
|
|
| .progress-card.active {
|
| display: block;
|
| }
|
|
|
| .progress-bar-container {
|
| width: 100%;
|
| height: 30px;
|
| background: #e0e0e0;
|
| border-radius: 15px;
|
| overflow: hidden;
|
| margin-bottom: 20px;
|
| }
|
|
|
| .progress-bar {
|
| height: 100%;
|
| background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
|
| width: 0%;
|
| transition: width 0.5s;
|
| display: flex;
|
| align-items: center;
|
| justify-content: center;
|
| color: white;
|
| font-weight: 600;
|
| }
|
|
|
| .status-box {
|
| background: #f5f5f5;
|
| padding: 20px;
|
| border-radius: 8px;
|
| margin-bottom: 20px;
|
| }
|
|
|
| .status-box h3 {
|
| color: #667eea;
|
| margin-bottom: 10px;
|
| }
|
|
|
| .status-box p {
|
| color: #666;
|
| line-height: 1.6;
|
| }
|
|
|
| .log-box {
|
| background: #1e1e1e;
|
| color: #00ff00;
|
| padding: 20px;
|
| border-radius: 8px;
|
| font-family: 'Courier New', monospace;
|
| font-size: 0.9em;
|
| max-height: 300px;
|
| overflow-y: auto;
|
| margin-top: 20px;
|
| }
|
|
|
| .log-box p {
|
| margin-bottom: 5px;
|
| }
|
|
|
| .folders-list {
|
| background: #f5f5f5;
|
| padding: 15px;
|
| border-radius: 8px;
|
| margin-top: 10px;
|
| max-height: 200px;
|
| overflow-y: auto;
|
| }
|
|
|
| .folder-item {
|
| padding: 10px;
|
| background: white;
|
| margin-bottom: 5px;
|
| border-radius: 5px;
|
| cursor: pointer;
|
| transition: background 0.2s;
|
| }
|
|
|
| .folder-item:hover {
|
| background: #667eea;
|
| color: white;
|
| }
|
|
|
| .status-idle { color: #999; }
|
| .status-running { color: #667eea; }
|
| .status-completed { color: #4caf50; }
|
| .status-error { color: #f44336; }
|
|
|
| .alert {
|
| padding: 15px;
|
| border-radius: 8px;
|
| margin-bottom: 20px;
|
| display: none;
|
| }
|
|
|
| .alert.show {
|
| display: block;
|
| }
|
|
|
| .alert-success {
|
| background: #d4edda;
|
| color: #155724;
|
| border: 1px solid #c3e6cb;
|
| }
|
|
|
| .alert-error {
|
| background: #f8d7da;
|
| color: #721c24;
|
| border: 1px solid #f5c6cb;
|
| }
|
|
|
| .spinner {
|
| display: inline-block;
|
| width: 20px;
|
| height: 20px;
|
| border: 3px solid rgba(255,255,255,.3);
|
| border-radius: 50%;
|
| border-top-color: #fff;
|
| animation: spin 1s ease-in-out infinite;
|
| }
|
|
|
| @keyframes spin {
|
| to { transform: rotate(360deg); }
|
| }
|
| </style>
|
| </head>
|
| <body>
|
| <div class="container">
|
|
|
| <div class="header">
|
| <h1>📚 AI Book Extraction System</h1>
|
| <p>Extract and explain book content using AI</p>
|
| </div>
|
|
|
|
|
| <div id="reconnectBanner" class="reconnect-banner">
|
| 🔄 Reconnected! Found active extraction in progress...
|
| </div>
|
|
|
|
|
| <div id="alert" class="alert"></div>
|
|
|
|
|
| <div class="card" id="inputCard">
|
| <div class="input-group">
|
| <label for="folderName">📁 Enter Folder Name:</label>
|
| <input
|
| type="text"
|
| id="folderName"
|
| placeholder="e.g., math, physics, chemistry..."
|
| autocomplete="off"
|
| >
|
| </div>
|
|
|
| <button class="btn" id="startBtn" onclick="startExtraction()">
|
| 🚀 Start Extraction
|
| </button>
|
|
|
| <div style="text-align: center; margin: 20px 0; color: #999;">
|
| <p>OR</p>
|
| </div>
|
|
|
| <button class="btn" style="background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);" onclick="loadFolders()">
|
| 📂 Show Available Folders
|
| </button>
|
|
|
| <div id="foldersList" class="folders-list" style="display: none;"></div>
|
| </div>
|
|
|
|
|
| <div class="card progress-card" id="progressCard">
|
| <h2 style="color: #667eea; margin-bottom: 20px;">⚙️ Processing...</h2>
|
|
|
| <div class="progress-bar-container">
|
| <div class="progress-bar" id="progressBar">0%</div>
|
| </div>
|
|
|
| <div class="status-box">
|
| <h3>📊 Status</h3>
|
| <p><strong>Folder:</strong> <span id="folderNameDisplay">-</span></p>
|
| <p><strong>Current Page:</strong> <span id="currentPage">0</span> / <span id="totalPages">0</span></p>
|
| <p><strong>Status:</strong> <span id="statusText" class="status-idle">Idle</span></p>
|
| <p style="margin-top: 10px;"><strong>Message:</strong></p>
|
| <p id="statusMessage" style="font-style: italic;">Waiting to start...</p>
|
| </div>
|
|
|
| <div class="log-box" id="logBox">
|
| <p>System ready. Waiting for process to start...</p>
|
| </div>
|
| </div>
|
| </div>
|
|
|
| <script>
|
| let progressInterval = null;
|
| let logMessages = [];
|
| let hasCheckedStatus = false;
|
|
|
|
|
| window.addEventListener('load', function() {
|
| checkActiveExtraction();
|
| });
|
|
|
| function checkActiveExtraction() {
|
| fetch('/check_status')
|
| .then(response => response.json())
|
| .then(data => {
|
| if (data.has_active) {
|
|
|
| document.getElementById('reconnectBanner').classList.add('show');
|
| setTimeout(() => {
|
| document.getElementById('reconnectBanner').classList.remove('show');
|
| }, 5000);
|
|
|
|
|
| document.getElementById('inputCard').style.display = 'none';
|
| document.getElementById('progressCard').classList.add('active');
|
|
|
|
|
| document.getElementById('folderNameDisplay').textContent = data.progress.folder_name || 'Unknown';
|
|
|
|
|
| startProgressTracking();
|
|
|
| hasCheckedStatus = true;
|
| }
|
| })
|
| .catch(error => {
|
| console.error('Error checking status:', error);
|
| });
|
| }
|
|
|
| function showAlert(message, type) {
|
| const alert = document.getElementById('alert');
|
| alert.className = `alert alert-${type} show`;
|
| alert.textContent = message;
|
|
|
| setTimeout(() => {
|
| alert.classList.remove('show');
|
| }, 5000);
|
| }
|
|
|
| function startExtraction() {
|
| const folderName = document.getElementById('folderName').value.trim();
|
|
|
| if (!folderName) {
|
| showAlert('Please enter a folder name!', 'error');
|
| return;
|
| }
|
|
|
| const startBtn = document.getElementById('startBtn');
|
| startBtn.disabled = true;
|
| startBtn.innerHTML = '<span class="spinner"></span> Starting...';
|
|
|
| fetch('/start', {
|
| method: 'POST',
|
| headers: {
|
| 'Content-Type': 'application/json',
|
| },
|
| body: JSON.stringify({ folder_name: folderName })
|
| })
|
| .then(response => response.json())
|
| .then(data => {
|
| if (data.success) {
|
| showAlert(data.message, 'success');
|
| document.getElementById('inputCard').style.display = 'none';
|
| document.getElementById('progressCard').classList.add('active');
|
| document.getElementById('folderNameDisplay').textContent = folderName;
|
| startProgressTracking();
|
| } else {
|
| if (data.already_running) {
|
|
|
| document.getElementById('inputCard').style.display = 'none';
|
| document.getElementById('progressCard').classList.add('active');
|
| startProgressTracking();
|
| showAlert('Reconnected to active extraction!', 'success');
|
| } else {
|
| showAlert(data.message, 'error');
|
| startBtn.disabled = false;
|
| startBtn.innerHTML = '🚀 Start Extraction';
|
| }
|
| }
|
| })
|
| .catch(error => {
|
| showAlert('Error: ' + error.message, 'error');
|
| startBtn.disabled = false;
|
| startBtn.innerHTML = '🚀 Start Extraction';
|
| });
|
| }
|
|
|
| function startProgressTracking() {
|
| logMessages = [];
|
| if (progressInterval) {
|
| clearInterval(progressInterval);
|
| }
|
| progressInterval = setInterval(updateProgress, 1000);
|
| }
|
|
|
| function updateProgress() {
|
| fetch('/progress')
|
| .then(response => response.json())
|
| .then(data => {
|
| const currentPage = data.current_page || 0;
|
| const totalPages = data.total_pages || 0;
|
| const status = data.status || 'idle';
|
| const message = data.message || '';
|
| const folderName = data.folder_name || '';
|
|
|
|
|
| if (folderName) {
|
| document.getElementById('folderNameDisplay').textContent = folderName;
|
| }
|
|
|
|
|
| const percentage = totalPages > 0 ? Math.round((currentPage / totalPages) * 100) : 0;
|
| document.getElementById('progressBar').style.width = percentage + '%';
|
| document.getElementById('progressBar').textContent = percentage + '%';
|
|
|
|
|
| document.getElementById('currentPage').textContent = currentPage;
|
| document.getElementById('totalPages').textContent = totalPages;
|
|
|
| const statusText = document.getElementById('statusText');
|
| statusText.textContent = status.toUpperCase();
|
| statusText.className = 'status-' + status;
|
|
|
| document.getElementById('statusMessage').textContent = message;
|
|
|
|
|
| if (message && !logMessages.includes(message)) {
|
| logMessages.push(message);
|
| const logBox = document.getElementById('logBox');
|
| const p = document.createElement('p');
|
| p.textContent = '> ' + message;
|
| logBox.appendChild(p);
|
| logBox.scrollTop = logBox.scrollHeight;
|
| }
|
|
|
|
|
| if (status === 'completed') {
|
| clearInterval(progressInterval);
|
| showAlert('✅ Extraction completed successfully! File uploaded to GitHub.', 'success');
|
| setTimeout(() => {
|
| location.reload();
|
| }, 5000);
|
| } else if (status === 'error') {
|
| clearInterval(progressInterval);
|
| showAlert('❌ Extraction failed. Check the logs for details.', 'error');
|
| }
|
| })
|
| .catch(error => {
|
| console.error('Error fetching progress:', error);
|
| });
|
| }
|
|
|
| function loadFolders() {
|
| fetch('/folders')
|
| .then(response => response.json())
|
| .then(data => {
|
| if (data.success) {
|
| const foldersList = document.getElementById('foldersList');
|
| foldersList.innerHTML = '';
|
|
|
| if (data.folders.length === 0) {
|
| foldersList.innerHTML = '<p style="text-align: center; color: #999;">No folders found</p>';
|
| } else {
|
| data.folders.forEach(folder => {
|
| const div = document.createElement('div');
|
| div.className = 'folder-item';
|
| div.textContent = '📁 ' + folder;
|
| div.onclick = () => {
|
| document.getElementById('folderName').value = folder;
|
| foldersList.style.display = 'none';
|
| };
|
| foldersList.appendChild(div);
|
| });
|
| }
|
|
|
| foldersList.style.display = 'block';
|
| } else {
|
| showAlert('Error loading folders: ' + data.message, 'error');
|
| }
|
| })
|
| .catch(error => {
|
| showAlert('Error: ' + error.message, 'error');
|
| });
|
| }
|
|
|
|
|
| document.getElementById('folderName').addEventListener('keypress', function(e) {
|
| if (e.key === 'Enter') {
|
| startExtraction();
|
| }
|
| });
|
|
|
|
|
| setInterval(() => {
|
| if (!hasCheckedStatus) return;
|
|
|
| fetch('/check_status')
|
| .then(response => response.json())
|
| .then(data => {
|
| if (data.has_active) {
|
|
|
| if (!document.getElementById('progressCard').classList.contains('active')) {
|
| document.getElementById('inputCard').style.display = 'none';
|
| document.getElementById('progressCard').classList.add('active');
|
| if (!progressInterval) {
|
| startProgressTracking();
|
| }
|
| }
|
| }
|
| })
|
| .catch(error => {
|
| console.error('Error in background check:', error);
|
| });
|
| }, 3000);
|
| </script>
|
| </body>
|
| </html> |