Skip to content

Commit 60f9206

Browse files
author
mekotools
committed
feat(server): expose transcription progress via GET /progress
Adds a pollable progress endpoint to the HTTP server: while a transcription runs, do_transcribe updates g_server_progress (0..100) in its chunk loop; GET /progress returns {"busy": bool, "progress": -1..100}. Motivation: the polyschnack webapp needs honest progress for long diarization/ASR jobs; the server previously had no progress channel over HTTP (the whisper progress callback only printed to stderr). Notes: - One job per container today, so a single atomic is honest; with --server-workers concurrency this needs per-request scoping (future work). - progress_scope guard resets busy/progress on every exit path.
1 parent 8c1e297 commit 60f9206

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

examples/cli/crispasr_server.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,18 @@ struct stage_scope {
451451

452452
// Load audio from a multipart file upload, transcribe it, return result.
453453
// Acquires model_mutex internally.
454+
455+
// Change 150 (polyschnack): per-server progress for the webapp. One job per
456+
// container today, so a single atomic is honest; with --server-workers
457+
// concurrency this needs per-request scoping (future work).
458+
static std::atomic<int> g_server_progress{-1}; // 0..100, -1 = idle
459+
static std::atomic<bool> g_server_busy{false};
460+
struct progress_scope {
461+
explicit progress_scope() { g_server_progress = 0; g_server_busy = true; }
462+
~progress_scope() { g_server_busy = false; g_server_progress = -1; }
463+
progress_scope(const progress_scope&) = delete;
464+
progress_scope& operator=(const progress_scope&) = delete;
465+
};
454466
static transcription_result do_transcribe(const httplib::MultipartFormData& audio_file, CrispasrBackend* backend,
455467
std::mutex& model_mutex, whisper_params rp, bool need_timestamps,
456468
fireredpunc_context* punc_ctx = nullptr, pcs_context* pcs_ctx = nullptr,
@@ -459,6 +471,7 @@ static transcription_result do_transcribe(const httplib::MultipartFormData& audi
459471
truecaser_lstm_context* tc_lstm_ctx = nullptr) {
460472
transcription_result result;
461473
result.language = rp.language;
474+
progress_scope _progress; // Change 150: /progress liefert 0..100
462475

463476
if (rp.verbose)
464477
fprintf(stderr, "crispasr-server: processing '%s' (%zu bytes)\n", log_sanitize(audio_file.filename).c_str(),
@@ -731,6 +744,7 @@ static transcription_result do_transcribe(const httplib::MultipartFormData& audi
731744

732745
for (size_t i = 0; i < slices.size(); ++i) {
733746
const auto& sl = slices[i];
747+
g_server_progress = (int)((i + 1) * 100 / slices.size()); // Change 150
734748
auto tc0 = std::chrono::steady_clock::now();
735749
auto segs = backend->transcribe(pcmf32.data() + sl.start, sl.end - sl.start, sl.t0_cs, rp);
736750
if (rp.return_logits)
@@ -2281,6 +2295,18 @@ int crispasr_run_server(whisper_params& params, const std::string& host, int por
22812295
}
22822296
});
22832297

2298+
// -----------------------------------------------------------------------
2299+
// GET /progress — Change 150 (polyschnack): 0..100 des aktuellen Jobs.
2300+
// busy=false → idle; progress=-1 → kein Fortschritt bekannt.
2301+
// -----------------------------------------------------------------------
2302+
svr.Get("/progress", [&](const Request&, Response& res) {
2303+
char buf[96];
2304+
snprintf(buf, sizeof(buf), "{\"busy\": %s, \"progress\": %d}",
2305+
g_server_busy.load() ? "true" : "false",
2306+
g_server_progress.load());
2307+
res.set_content(buf, "application/json");
2308+
});
2309+
22842310
// -----------------------------------------------------------------------
22852311
// GET /backends
22862312
// -----------------------------------------------------------------------

0 commit comments

Comments
 (0)