|
|
<!DOCTYPE html> |
|
|
<html lang="en"> |
|
|
<head> |
|
|
<meta charset="UTF-8"> |
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
|
<title>Caption Flow Server Dashboard - {{ flow_id }}</title> |
|
|
<style> |
|
|
body { |
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; |
|
|
margin: 0; |
|
|
padding: 20px; |
|
|
background-color: #f4f7f9; |
|
|
color: #333; |
|
|
} |
|
|
.container { |
|
|
max-width: 1200px; |
|
|
margin: auto; |
|
|
background: #fff; |
|
|
padding: 30px; |
|
|
border-radius: 12px; |
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); |
|
|
} |
|
|
h1 { |
|
|
color: #1e3a8a; |
|
|
border-bottom: 2px solid #eff6ff; |
|
|
padding-bottom: 10px; |
|
|
margin-bottom: 20px; |
|
|
} |
|
|
h2 { |
|
|
color: #3b82f6; |
|
|
margin-top: 30px; |
|
|
border-left: 4px solid #93c5fd; |
|
|
padding-left: 10px; |
|
|
} |
|
|
.status-box { |
|
|
padding: 15px; |
|
|
border-radius: 8px; |
|
|
font-weight: bold; |
|
|
margin-bottom: 20px; |
|
|
display: inline-block; |
|
|
} |
|
|
.status-ready { background-color: #d1fae5; color: #065f46; } |
|
|
.status-processing { background-color: #fef3c7; color: #b45309; } |
|
|
.form-group { |
|
|
margin-bottom: 15px; |
|
|
} |
|
|
label { |
|
|
display: block; |
|
|
margin-bottom: 5px; |
|
|
font-weight: 600; |
|
|
} |
|
|
input[type="text"], input[type="number"] { |
|
|
width: 100%; |
|
|
padding: 10px; |
|
|
border: 1px solid #ccc; |
|
|
border-radius: 6px; |
|
|
box-sizing: border-box; |
|
|
font-size: 16px; |
|
|
} |
|
|
button { |
|
|
background-color: #3b82f6; |
|
|
color: white; |
|
|
padding: 10px 15px; |
|
|
border: none; |
|
|
border-radius: 6px; |
|
|
cursor: pointer; |
|
|
font-size: 16px; |
|
|
transition: background-color 0.2s; |
|
|
} |
|
|
button:hover { |
|
|
background-color: #2563eb; |
|
|
} |
|
|
.server-list { |
|
|
list-style: none; |
|
|
padding: 0; |
|
|
} |
|
|
.server-item { |
|
|
background-color: #f9fafb; |
|
|
border: 1px solid #eee; |
|
|
padding: 15px; |
|
|
margin-bottom: 10px; |
|
|
border-radius: 8px; |
|
|
display: flex; |
|
|
justify-content: space-between; |
|
|
align-items: center; |
|
|
} |
|
|
.server-item .url { |
|
|
flex-grow: 1; |
|
|
font-family: monospace; |
|
|
font-size: 14px; |
|
|
} |
|
|
.server-item .stats { |
|
|
margin-left: 20px; |
|
|
font-size: 0.9em; |
|
|
color: #6b7280; |
|
|
} |
|
|
.server-item .status { |
|
|
font-weight: bold; |
|
|
color: #10b981; |
|
|
margin-right: 10px; |
|
|
} |
|
|
.server-item .status.busy { |
|
|
color: #f59e0b; |
|
|
} |
|
|
.remove-btn { |
|
|
background-color: #ef4444; |
|
|
} |
|
|
.remove-btn:hover { |
|
|
background-color: #dc2626; |
|
|
} |
|
|
.message-area { |
|
|
margin-top: 20px; |
|
|
padding: 10px; |
|
|
border-radius: 6px; |
|
|
display: none; |
|
|
} |
|
|
.message-success { background-color: #d1fae5; color: #065f46; } |
|
|
.message-error { background-color: #fee2e2; color: #991b1b; } |
|
|
.grid { |
|
|
display: grid; |
|
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); |
|
|
gap: 20px; |
|
|
} |
|
|
.card { |
|
|
background: #fff; |
|
|
padding: 20px; |
|
|
border-radius: 8px; |
|
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); |
|
|
border: 1px solid #e5e7eb; |
|
|
} |
|
|
.card-header { |
|
|
font-size: 1.1em; |
|
|
font-weight: 600; |
|
|
margin-bottom: 15px; |
|
|
color: #1f2937; |
|
|
} |
|
|
</style> |
|
|
</head> |
|
|
<body> |
|
|
<div class="container"> |
|
|
<h1>Caption Flow Server: {{ flow_id }}</h1> |
|
|
|
|
|
<div class="status-box status-{{ 'processing' if status == 'processing' else 'ready' }}"> |
|
|
System Status: {{ status.capitalize() }} |
|
|
</div> |
|
|
|
|
|
<div class="grid"> |
|
|
<div class="card"> |
|
|
<div class="card-header">Processing State</div> |
|
|
<p><strong>Manager URL:</strong> <a href="{{ manager_url }}" target="_blank">{{ manager_url }}</a></p> |
|
|
<p><strong>Processed Files Count:</strong> {{ processed_files_count }}</p> |
|
|
<p><strong>Last Processed Course:</strong> {{ last_course if last_course else 'N/A' }}</p> |
|
|
<p><strong>Last Processed Index:</strong> {{ last_index }}</p> |
|
|
</div> |
|
|
|
|
|
<div class="card"> |
|
|
<div class="card-header">Start New Course Processing</div> |
|
|
<form id="process-form"> |
|
|
<div class="form-group"> |
|
|
<label for="course_name">Course Name Prefix (e.g., DAREEFSA)</label> |
|
|
<input type="text" id="course_name" name="course_name" required> |
|
|
</div> |
|
|
<div class="form-group"> |
|
|
<label for="start_index">Start Image Index (0 to start from beginning)</label> |
|
|
<input type="number" id="start_index" name="start_index" value="0" min="0"> |
|
|
</div> |
|
|
<button type="submit">Start Processing</button> |
|
|
</form> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<h2>Caption Servers (Total: {{ total_servers }}, Busy: {{ busy_servers }})</h2> |
|
|
<div id="message-server" class="message-area"></div> |
|
|
|
|
|
<div class="card"> |
|
|
<div class="card-header">Add New Server</div> |
|
|
<form id="add-server-form" style="display: flex; gap: 10px;"> |
|
|
<input type="text" id="new_server_url" name="server_url" placeholder="Enter server URL (e.g., https://user-space.hf.space/analyze)" required style="flex-grow: 1;"> |
|
|
<button type="submit">Add Server</button> |
|
|
</form> |
|
|
</div> |
|
|
|
|
|
<ul class="server-list" id="server-list"> |
|
|
{% for server in servers %} |
|
|
<li class="server-item" data-url="{{ server.url }}"> |
|
|
<span class="url">{{ server.url }}</span> |
|
|
<span class="stats"> |
|
|
<span class="status {% if server.busy %}busy{% endif %}">{{ 'BUSY' if server.busy else 'READY' }}</span> |
|
|
| Processed: {{ server.total_processed }} |
|
|
| FPS: {{ "%.2f"|format(server.fps) }} |
|
|
</span> |
|
|
<button class="remove-btn" onclick="removeServer('{{ server.url }}')">Remove</button> |
|
|
</li> |
|
|
{% endfor %} |
|
|
</ul> |
|
|
</div> |
|
|
|
|
|
<script> |
|
|
const serverList = document.getElementById('server-list'); |
|
|
const messageServer = document.getElementById('message-server'); |
|
|
const messageProcess = document.getElementById('message-process'); |
|
|
|
|
|
function showMessage(element, type, message) { |
|
|
element.className = `message-area message-${type}`; |
|
|
element.textContent = message; |
|
|
element.style.display = 'block'; |
|
|
setTimeout(() => { |
|
|
element.style.display = 'none'; |
|
|
}, 5000); |
|
|
} |
|
|
|
|
|
document.getElementById('add-server-form').addEventListener('submit', async function(e) { |
|
|
e.preventDefault(); |
|
|
const urlInput = document.getElementById('new_server_url'); |
|
|
const serverUrl = urlInput.value.trim(); |
|
|
|
|
|
try { |
|
|
const response = await fetch('/add_server', { |
|
|
method: 'POST', |
|
|
headers: { |
|
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
|
}, |
|
|
body: new URLSearchParams({ server_url: serverUrl }) |
|
|
}); |
|
|
|
|
|
const result = await response.json(); |
|
|
|
|
|
if (response.ok) { |
|
|
showMessage(messageServer, 'success', result.message); |
|
|
|
|
|
const newItem = document.createElement('li'); |
|
|
newItem.className = 'server-item'; |
|
|
newItem.setAttribute('data-url', result.server.url); |
|
|
newItem.innerHTML = ` |
|
|
<span class="url">${result.server.url}</span> |
|
|
<span class="stats"> |
|
|
<span class="status">READY</span> |
|
|
| Processed: 0 |
|
|
| FPS: 0.00 |
|
|
</span> |
|
|
<button class="remove-btn" onclick="removeServer('${result.server.url}')">Remove</button> |
|
|
`; |
|
|
serverList.appendChild(newItem); |
|
|
urlInput.value = ''; |
|
|
} else { |
|
|
showMessage(messageServer, 'error', result.detail || 'Failed to add server.'); |
|
|
} |
|
|
} catch (error) { |
|
|
showMessage(messageServer, 'error', 'Network error or server unreachable.'); |
|
|
} |
|
|
}); |
|
|
|
|
|
async function removeServer(serverUrl) { |
|
|
if (!confirm(`Are you sure you want to remove server: ${serverUrl}?`)) { |
|
|
return; |
|
|
} |
|
|
|
|
|
try { |
|
|
const response = await fetch('/remove_server', { |
|
|
method: 'POST', |
|
|
headers: { |
|
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
|
}, |
|
|
body: new URLSearchParams({ server_url: serverUrl }) |
|
|
}); |
|
|
|
|
|
const result = await response.json(); |
|
|
|
|
|
if (response.ok) { |
|
|
showMessage(messageServer, 'success', result.message); |
|
|
|
|
|
const itemToRemove = document.querySelector(`.server-item[data-url="${serverUrl}"]`); |
|
|
if (itemToRemove) { |
|
|
itemToRemove.remove(); |
|
|
} |
|
|
} else { |
|
|
showMessage(messageServer, 'error', result.detail || 'Failed to remove server.'); |
|
|
} |
|
|
} catch (error) { |
|
|
showMessage(messageServer, 'error', 'Network error or server unreachable.'); |
|
|
} |
|
|
} |
|
|
|
|
|
document.getElementById('process-form').addEventListener('submit', async function(e) { |
|
|
e.preventDefault(); |
|
|
const courseName = document.getElementById('course_name').value.trim(); |
|
|
const startIndex = parseInt(document.getElementById('start_index').value, 10); |
|
|
|
|
|
try { |
|
|
const response = await fetch('/process_course', { |
|
|
method: 'POST', |
|
|
headers: { |
|
|
'Content-Type': 'application/json', |
|
|
}, |
|
|
body: JSON.stringify({ course_name: courseName, start_index: startIndex }) |
|
|
}); |
|
|
|
|
|
const result = await response.json(); |
|
|
const processMessageArea = document.querySelector('.card:nth-child(2) .form-group').parentElement.querySelector('#message-process') || document.createElement('div'); |
|
|
processMessageArea.id = 'message-process'; |
|
|
if (!processMessageArea.parentElement) { |
|
|
document.querySelector('.card:nth-child(2)').appendChild(processMessageArea); |
|
|
} |
|
|
|
|
|
if (response.ok) { |
|
|
showMessage(processMessageArea, 'success', `Processing started for course: ${result.course_name} from index: ${result.start_index}.`); |
|
|
} else { |
|
|
showMessage(processMessageArea, 'error', result.detail || 'Failed to start processing.'); |
|
|
} |
|
|
} catch (error) { |
|
|
const processMessageArea = document.querySelector('.card:nth-child(2) .form-group').parentElement.querySelector('#message-process') || document.createElement('div'); |
|
|
processMessageArea.id = 'message-process'; |
|
|
if (!processMessageArea.parentElement) { |
|
|
document.querySelector('.card:nth-child(2)').appendChild(processMessageArea); |
|
|
} |
|
|
showMessage(processMessageArea, 'error', 'Network error or server unreachable.'); |
|
|
} |
|
|
}); |
|
|
</script> |
|
|
</body> |
|
|
</html> |
|
|
|