Skip to content

Commit ade7f92

Browse files
committed
Frontend: dirty queue display
1 parent d5d684a commit ade7f92

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

examples/server/frontend.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const std::string html_content = R"xxx(
1010
body {
1111
font-family: Arial, sans-serif;
1212
display: flex;
13+
flex-direction: column;
1314
align-items: center;
1415
justify-content: center;
1516
height: 100vh;
@@ -254,8 +255,17 @@ const std::string html_content = R"xxx(
254255
<canvas id="imageCanvas" width="500" height="500"></canvas>
255256
</div>
256257
</div>
258+
<div class="line">
259+
<p>Current task status: <span id="status"> -- </span> | Queue: <span id="queued_tasks">0</span></p>
260+
</div>
257261
)xxx" R"xxx(
258262
<script>
263+
let queued_tasks = 0;
264+
async function update_queue() {
265+
const display = document.getElementById('queued_tasks');
266+
display.innerHTML = queued_tasks;
267+
}
268+
259269
const modelIdElement = document.getElementById('model-id');
260270
261271
async function fetchModelId() {
@@ -465,7 +475,7 @@ const std::string html_content = R"xxx(
465475
}
466476
)xxx" R"xxx(
467477
468-
fetchSampleMethods();
478+
fetchSampleMethods();
469479
fetchSchedules();
470480
fetchPreviewMethods();
471481
fetchModelsEncodersAE();
@@ -475,6 +485,9 @@ const std::string html_content = R"xxx(
475485
476486
477487
async function generateImage() {
488+
queued_tasks++;
489+
update_queue();
490+
478491
const prompt = document.getElementById('prompt').value;
479492
const neg_prompt = document.getElementById('neg_prompt').value;
480493
const width = document.getElementById('width').value;
@@ -575,6 +588,7 @@ const std::string html_content = R"xxx(
575588
}, 0);
576589
}
577590
status = statusData.status;
591+
document.getElementById('status').innerHTML = status;
578592
579593
if (status === 'Done' || (status === 'Working' && statusData.data.length > 0)) {
580594
const imageData = statusData.data[0].data;
@@ -596,6 +610,8 @@ const std::string html_content = R"xxx(
596610
597611
await new Promise(resolve => setTimeout(resolve, 250));
598612
}
613+
queued_tasks--;
614+
update_queue();
599615
}
600616
601617
document.querySelectorAll('.prompt-input,.param-input').forEach(input => {

0 commit comments

Comments
 (0)