Spaces:
Running
Running
Commit History
-
Revert this session's changes back to the last known-good version Running
Restores the tree to 4b38f72 exactly. The reported result was worse than the version that was already working, across the swap output, the head swap and the app generally, so the right move is to put the working version back rather than keep patching on top of it. Reverts, newest first: f008eb7 head-swap pose gate + warnings in the UI 0ab4ea6 seam blend against base instead of target b1cd367 workflow PDF + binary .gitattributes rules f25d3bf glasses transfer made opt-in 74dd70d hair matte fix + removal of the crude hair fallback b60d8aa background jobs + Head Swap toggle ddb0022 head-only super-resolution 27e2136 composite onto the full-resolution original 9e549b6 grain confined to the parsed head bb3e953 Control Panel sign-in inside the Hugging Face iframe e522792 Flask debug off by default + threaded pre-warm 27bac33 scene-harmonisation regressions Nothing is lost: each of the above is still in history and can be cherry-picked back individually o…f4e824d -
Refuse a head swap when the two heads face different ways, and say so
full_head_swap fits a 2D similarity transform, so it can slide, spin and scale the source head but cannot turn it. Transplanting a head that is nodded down onto a body with its chin up lands visibly crooked however well the seam is blended, and nothing downstream can correct it. Measured against the Library target (pitch +14, yaw 0): of four test photos, one differed by 26 degrees of pitch, one by 27 of yaw, one by 30 and 20. Those are exactly the results that come out misaligned. The pose delta is now checked before transplanting. Past 25 degrees of pitch or yaw the head swap is skipped and the clean face swap is used instead; between 15 and 25 it runs but says the alignment may be imperfect. Roll is excluded on purpose — it is in-plane and the transform already corrects it. A 20-degree case was checked by eye and still looks right, so the cut sits above it. The frontend never rendered the warnings array at all, so this explanation — and the pre-existing "face is very small" notes …f008eb7 -
Stop the seam blend from erasing the head swap
With the Head Swap toggle on, the output was indistinguishable from an ordinary face swap. The head transplant ran, but step 3b then blended the swapped face against `target` — the ORIGINAL scene — rather than against `base`, the image the head swap had just produced. Everywhere outside the face mask, which is exactly where the transplanted head shape and hair live, the result was pulled back to the untouched target. Measured on the Library target: full_head_swap changes the frame by mean 0.90, but only 0.29 survived the blend — roughly two thirds of the effect discarded. Blending against `base` retains 0.90, and end to end the toggle now changes 1.69% of pixels by more than 15 levels instead of producing the same picture. `base` is `target` whenever the head swap is off, so nothing changes there. The file's own comment already warned about this trap for the hair step; the same one was left open for the head swap. Also drops the composite feather from 0.025 to 0.012, which measured …0ab4ea6 -
Add a workflow PDF, and stop git rewriting line endings inside binaries
docs/WORKFLOW.pdf documents how the project actually works: architecture, the submit-and-poll request flow, every pipeline stage with its measured CPU cost, the deploy path from a push to a running Space, and the behaviour that is easy to misread from the code (why hair and glasses are opt-in, why quality is scored before the harmonise stage, CPU vs GPU differences). It is generated by scripts/make_workflow_pdf.py rather than drawn by hand, so it can be regenerated when the pipeline changes instead of quietly going stale. Boxes size themselves from their content — a hand-tuned height had already let one section overflow its border. .gitattributes gained binary rules for pdf/png/jpg/onnx/pth. Adding the PDF made git announce "LF will be replaced by CRLF" for it, which would have corrupted the file; the existing image assets were unprotected in the same way. Verified the committed blob is byte-identical to the generated file.b1cd367 -
Make glasses transfer opt-in — it was disfiguring glasses-wearing sources
transfer_glasses warps the source's spectacles onto the swapped face using a two-point eye transform. Run against a real source who wears glasses, that lands as a semi-transparent, misaligned lens shape floating over the face rather than as spectacles: clearly worse than the clean swap beside it, which simply doesn't carry the glasses over. It was on by default, so every glasses-wearing user got that. Now opt-in via keep_glasses=1, matching how head swap and hair transfer are already gated. Both the request default and the worker default were changed, or one would have overridden the other. 14 tests pass.f25d3bf -
Fix the empty hair matte, and stop pasting hair when HairFastGAN is unavailable
Two separate hair problems, found by running the pipeline on real photos. _soft_hair_matte parsed a very wide crop so long hair wouldn't be cut off before parsing, but that also shrinks the head inside the 512x512 parse input and takes BiSeNet's hair confidence down with it. On a 66x77 face the matte peaked at 0.341 — nothing at all above the 0.4 that swap_hair thresholds at — so the mask came out empty and hair transfer silently did nothing at all. It now keeps the wide crop when it is confident and tightens only when it is not; across five test photos the matte went from 0.341/0.00% usable to 0.75-0.84, all usable. That alone made things worse, though: with a mask to work from, the fallback path warps the source's hair straight into the scene and composites a smeared, semi-transparent blob over the head — the pasted-hair artifact this project has been chasing. It is plainly worse than keeping the target's hair, which the clean face swap already produces. So the fallback is gone. H…74dd70d
-
Run swaps as background jobs, and add a Head Swap toggle to the app page
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 …b60d8aa -
Super-resolve the head only, which makes real SR affordable on CPU
RealESRGAN was GPU-only: on CPU a 4x pass over the full frame takes ~20 minutes here, so the free tier fell back to a plain Lanczos resize and the "4K" download was pure interpolation. Now that everything outside the changed region is composited straight from the full-resolution original, the background is already native and has nothing for a super-resolution model to reconstruct. Only the head came through the swap's 128x128 bottleneck, so RealESRGAN now runs on that crop alone and Lanczos covers the rest, feathered at the crop edge. Measured on the Library target (CPU, 1086x1448 -> 4344x5792): head-only SR takes 370s against ~1200s for the full frame, and high-frequency detail in the face region rises from 5.9 to 19.9. GPU behaviour is unchanged when no bbox is given. Not yet safe to deploy synchronously — 370s exceeds the request timeout. The async job endpoint lands next.ddb0022 -
Keep the original photo's background instead of downscaling and interpolating it
The pipeline resizes the target to the working resolution (1024 on CPU) so the models stay affordable, then upscales the whole frame 4x for the download. For a 1086x1448 location photo that means everything — including the background and body, which the swap never touches — is halved in detail and then interpolated back up. The result is now composited back onto the untouched full-resolution target, pasting only the region the pipeline actually changed. The mask comes from a diff against the working-resolution target rather than a parsed head shape, so changes outside the head are carried over too: match_skin_to_source also recolours neck, arms and hands, and a head-only mask would silently drop that. Measured end-to-end on the Library target, in regions the swap never touches: background sharpness goes from ~34% of the original to 100% (bottom edge 97.6%), and the delivered image is now 1086x1448 native rather than 768x1024, so the 4x download is 4344x5792 instead of 3072x4096. No s…27e2136 -
Confine scene grain to the parsed head instead of a box around it
harmonize_to_scene built its mask from a rectangle around the face bbox, so the grain meant for the GAN-smooth face and hair was sprayed over everything sharing those bounds — background, bookshelves, clothing — dirtying the scene and leaving the box's own feathered edge visible in the result. It now parses the head/hair/neck shape (clamped to a generous head box so stray specks elsewhere can't pick up grain) and feathers it narrowly, just enough to fade at the hairline. Class 18 (hat) is included here only: the parser labels part of the hair as hat, and dropping it left an ungrained hole in the top of the head. _HEAD_CLASSES still excludes it for hair transfer, where it misfires. Measured on a self-swap of the Library target (768x1024, CPU), where the output should barely differ from the input: the mean pixel change from this step falls from 6.46 to 0.33, and the masked region from roughly half the frame to 2.4%. Background, shirt and shelves now come through untouched.9e549b6 -
Fix Control Panel Google sign-in inside the Hugging Face iframe
On huggingface.co the Space runs in a cross-origin iframe. The popup is blocked there, and the existing fallback called signInWithRedirect — which navigates THIS frame to Google. Google refuses to be embedded and answers 403 ("you do not have access to this document"), which is the error the Control Panel showed. When framed we now never redirect. Instead the login card offers to reopen the app in a top-level tab, where the normal popup flow works; the button is shown up front while framed, not only after a failed attempt. Also wires up getRedirectResult, which was exported from firebase.js but never called. The non-framed redirect path could previously fail silently: you came back from Google and just saw the login screen again with no error.bb3e953 -
Turn Flask debug OFF by default and pre-warm models without blocking startup
Nothing sets FLASK_DEBUG in the Dockerfile, startup.sh or the Space config, and both reads defaulted it to "true" — so the deployed Space served the Werkzeug interactive debugger on the public internet, and CORS took the localhost-only dev branch instead of the intended production one. The default is now off (opt in locally with FLASK_DEBUG=true), which also means _prewarm_models() no longer gets skipped, so the first swap doesn't pay for loading buffalo_l + inswapper + GFPGAN on the request path. It runs in a daemon thread so the port still binds immediately — startup.sh backgrounds the model downloads for exactly that reason, since HF kills a container that doesn't answer on its port within ~60s. Verified locally: "Debug mode: off", port bound while the pre-warm ran, and /api/locations served 200 during it.e522792 -
Fix scene-harmonisation regressions: quality scores, skin-tone reversal, long-hair gap
Three bugs in the harmonise pass (step 8) and its wiring: 1. Grain was injected BEFORE compute_quality_score ran on the same image, so the deliberate noise fed straight into the naturalness noise-penalty and the blend discontinuity term — the "make it look photographed" step was lowering the app's own reported quality on every swap. Quality + alignment are now scored first; harmonise still runs last before the output is encoded, so the grain survives into both the preview and the 4K download. 2. The colour cast sampled scene_mean over the WHOLE target frame, which still contains the original target face (target is never overwritten by the swap). That dragged the head's colour back toward the tone of the face it replaced, partially undoing match_skin_to_source one step earlier. It now samples only outside the head mask, and works in LAB with the same darken-only L rule as _match_lighting, so a bright background can't wash hair/skin to grey/silver. 3. The…27bac33
-
Add scene-harmonisation final pass: match the photo's grain + colour cast over the swapped head so the GAN-smooth face/hair stop looking synthetic/pasted and read as photographed with the scene
4b38f72 -
Hair robustness (100-img batch): lighting match only DARKENS hair (no grey wash on bright bg) + conservative grey-edge trim that won't cut lit/highlighted hair
1addd52
-
Fix facial discolour patches: restrict the neck/body skin pass to strictly below the chin (it was recolouring lips + cheek-ring -> patches on the face)
c5fbe15 -
Hair edge: soft strand edge for both paths (loosen clamp) + remove portrait grey crown by COLOUR not cropping -> no website grey line AND no hard cut-out, local/HF identical
5f1915f -
Fix website grey hair line: raise scene-fill threshold + clamp matte to confident-hair extent (kills the faint grey crown haze); drop guided filter for local/HF parity (no ximgproc on HF)
2cf928a -
Hair/forehead high-precision edge via guided filter (edge-aware matte) + gentle neck/body skin pass; opencv-contrib-headless on HF for ximgproc
1544cc7 -
Hair edge: composite with BiSeNet SOFTMAX hair matte (soft strand alpha) instead of a feathered binary mask -> real wispy hair edges, no cut-paste look, both genders
6ae45af -
Hair edge: smoother feather (0.025) for natural soft edges both genders, no hard cut-off; gentler lighting keeps it grey-free
324e77e -
Hair edge: crisper feather + erode-to-solid + gentler lighting match -> natural hairline, no grey fringe on dark hair
0d2a722 -
Hair blend: fill portrait grey padding with the scene before feathering (kills the blurry pasted halo) + tighter edge feather -> natural hair edges
34e8dd6
-
Hair swap: run Laplacian blend BEFORE hair (it was overwriting transferred hair with target's); opaque core + soft edge + recolour residual old hair for a seamless blend, both genders
e8b68af -
Skin tone: single uniform LAB offset over whole skin (no gate/per-region) -> no patches; verified clean across 10 tones light-to-dark, strength 0.92
8478059 -
Skin tone: recolour face-skin + body to SOURCE complexion (sampled from clean parsed skin, lips/eyes excluded, relative luminance gate) — clean on normal faces
ddb96a3 -
Skin tone: leave face untouched (swap already source-toned), only lift neck/arms/hands to match face — fixes blue/blotchy face patch
e711814 -
Move skin-tone match to final pipeline step so the Laplacian blend can't undo it (output skin now matches source across whole body); strength 0.9
5b7670e -
Skin tone: drive face+neck+body to SOURCE complexion (per-region delta), with luminance gate so beard/brows don't go blue
e3164c8 -
Skin tone: blend across whole body (face+neck+arms+hands) via adaptive chroma mask, clothes/background excluded
9d2db57 -
Fix close-up selfie detection: pad margin so face-fills-frame photos are found (0 faces -> crude paste was the no-hair/skin bug)
f0e4246 -
Fix hair composite: widen parse crop + region clamp so long hair transfers into scene (re-enable hair by default)
1940cda -
Hair swap back to opt-in: in-scene hair composite loses the hair (verified)
d189e1b -
Enable source hair+neck transfer by default (HairFastGAN on GPU, BiSeNet fallback)
8bcbc72
-
Remove percentage from loading bar
d69a33b -
Loading bar: motivational admission-nudging messages instead of process steps
1d240a0 -
Tighten skin-tone match 0.75 -> 0.85 (closer to source; glasses transfer already on)
85ce30c -
Redesign loading tab: friendly messages (no internal pipeline jargon) + spinner/percentage
afbdbab -
Default to the clean face swap; make head-swap & hair-swap opt-in
The head-swap-first reorder + HairFastGAN hair step degraded the clean face swap that was already producing good results. Both are now OFF by default (opt-in via head_swap=1 / swap_hair=1). Default pipeline: face swap (main face) -> GFPGAN -> skin match -> glasses -> blend -> 4x upscale.ca509be -
Auto de-roll tilted source faces (eye-line alignment) before swap
8eed89d -
Add batch QA test harness (scripts/batch_test.py)
Swaps N source faces x gender x location on GPU, saves results + a contact-sheet grid per location + a metrics CSV (blend/delta_e/naturalness). Face-only by default (~7-9s/swap, full 3800 matrix ~7-8h overnight); --hair adds HairFastGAN (slow, for small samples). Drop diverse faces in tests/faces/<gender>/. Verified: 1 swap in 8.9s on the RTX 4060.8a16253 -
Wire HairFastGAN (GPU) into the swap pipeline for realistic hair transfer
- web_app Phase 5: use transfer_hair (HairFastGAN/StyleGAN) to generate the source's hairstyle, then composite it back onto the swap via swap_hair; falls back to the BiSeNet warp when HairFastGAN isn't available (CPU/no token) - requirements-hairfast.txt: local-GPU hair deps (clip-anytorch, face_alignment, lpips, kornia, gdown, dill, addict, ftfy, dlib) Verified: HairFastGAN produces a photoreal 1024 portrait on the RTX 4060.75fd366 -
GPU: 1536px working res on CUDA + GPU deploy files (Dockerfile.gpu, requirements-gpu.txt)
- web_app: working resolution 1536 on GPU (sharper composite/landmarks), 1024 on CPU - Dockerfile.gpu: CUDA 12.4 + cuDNN 9 base, torch cu121 + onnxruntime-gpu, builds React, runs on HF Pro GPU hardware - requirements-gpu.txt: GPU dependency set (onnxruntime-gpu 1.19.2) CPU Dockerfile kept as the default fallback.136db11 -
Enable GPU for InsightFace: auto-add CUDA12 + cuDNN9 DLL dirs on Windows
onnxruntime-gpu silently fell back to CPU (LoadLibrary error 126) because cuDNN 9 keeps its CUDA-12 DLLs in a versioned subfolder (CUDNN\vX\bin\12.x) that isn't on PATH. detector._ensure_cuda_dlls() auto-discovers the CUDA toolkit bin + cuDNN 12.x bin and prepends them before importing onnxruntime. Verified: InsightFace, GFPGAN and RealESRGAN all run on the RTX 4060. No-op on Linux. + GPU_ENHANCEMENT_PLAN.md runbook (incl. batch test harness).e323c6f -
Swap only the main subject + always run face swap (fixes the mess)
- swapper: swap ONLY the largest target face (and any >=45% of it), so background faces (notice-board photos, posters, reflections) are no longer swapped — that was the 'mess'. Sharpen only the swapped region. - web_app: pipeline order head -> face -> hair. Face swap now ALWAYS runs (a weak head-swap result no longer short-circuits it), then GFPGAN restore, skin-tone match, hair swap, glasses, Laplacian blend. Verified by rendering the full pipeline output.4a2b4cf -
Retry HF push on transient failures (Space busy building)
HF sometimes rejects a force-push while the Space is still rebuilding from the previous push, causing isolated red deploys. Retry up to 4 times with a 15s backoff before failing.2499381 -
Resolve all project errors: clean lint, tests, imports
- eslint: turn off overly-strict react-hooks/set-state-in-effect (legitimate data-fetch-on-change effects); fix react-hooks/purity by making cacheBust a lazy useState initializer (() => Date.now()) - LandingPage: last em-dash (in a comment) -> hyphen - .gitignore: dev temp files (backend.log, resp.txt, _diag_*.py) Verified green: 25/25 backend modules import, 14/14 pytest pass, eslint clean, frontend build clean.29b87a5 -
Revert swap-quality regressions: skin 0.92->0.75, glasses face-swap-path only
The 0.92 skin pull over-tinted faces and running glasses transfer on every swap could paste artifacts. Restored the balanced settings that produced clean results: skin-tone match at 0.75, glasses transferred only in the face-swap fallback path (the head-swap path already carries them).7d36805 -
Fix: list_locations resilient when message column missing (was showing 0)
If the locations table hasn't had the message column added yet, selecting it returned an error and the whole list came back empty. Now it retries without message, so locations always show; custom messages activate once the ALTER runs.83651d7
-
Custom per-location result messages + unique defaults; remove em-dashes & "4K"
Custom messages (Control Panel) - locations table gets a `message` column; /api/admin/location/message sets it (edit = any admin). Supports {name} and {location} placeholders, auto-filled - Control Panel: per-location "Edit message" action (prompt), shows a ✎ marker when a custom message exists - App result uses the owner's custom message for that location if set, else a built-in UNIQUE message per location (Library, ICT Dept, VLSI Lab, etc.) UI copy - Removed em-dashes from all visible text (replaced with hyphens/periods) - "Download 4K" -> "Download"; filename no longer suffixed _4k supabase_store: list_locations returns message; add set_message() supabase_schema.sql: add message column (+ ALTER for existing tables)0550cee