Spaces:
Running

aditya-rAj19 commited on
Commit
b60d8aa
·
1 Parent(s): ddb0022

Run swaps as background jobs, and add a Head Swap toggle to the app page

Browse files

Full-quality output takes minutes on the free CPU tier — head super-resolution
alone is ~6 minutes — which no HTTP request survives. /api/swap now validates
and decodes the inputs, then returns 202 with a job_id; the pipeline runs on a
worker thread and /api/swap/status/<job_id> reports real progress and finally
the result, in the same shape the synchronous endpoint returned.

Jobs run one at a time: the Space has 2 vCPUs that the models already saturate,
so overlapping swaps would just make each one slower. Results hold multi-MB
base64 images, so finished jobs expire after 20 minutes and the store is capped.

The pipeline moved into _perform_swap(), which takes plain options instead of
reading request.form and raises SwapError for input problems, so it no longer
depends on a request context.

The progress bar now follows the server's real stage instead of a timer that
animated a guess. The motivational captions still rotate on their own — the wait
is longer now, so there's more of it to fill, not less.

Head Swap is exposed as a toggle in the top-right corner of the app page,
mirroring the Home button. It transplants the whole head (shape + hair) rather
than just the inner face. Off by default, since it changes much more of the
photo.

Verified end-to-end against a local server: submit returns in 1.6s, progress
reports 2 -> 28 -> 40 -> 50 -> 78 -> 88 -> done, and both head_swap=0 and
head_swap=1 complete (alignment 92.4 / 92.1, blend 93.7, naturalness 98.0).
Frontend builds; 14 tests pass.

2 files changed +228 -29
Files changed (2)
frontend/src/pages/AppPage.jsx+70-10
web_app.py+158-19