HeadlinesBriefing favicon HeadlinesBriefing.com

Build a CPU‑Only Face Swap App on Google Colab

DEV Community •
×

Developers can now spin up a full‑featured face swap service inside a single Google Colab notebook without touching a GPU. The guide names the notebook FaceSwap.ipynb, clones a lightweight web UI from GitHub, and configures the InsightFace ONNX model to run entirely on CPU. Public access is achieved via a tunnel.

First, the script changes to /content, removes any prior copy, and pulls the repository. Next, it creates the hidden .insightface/models folder and downloads inswapper_128.onnx from Hugging Face, avoiding flaky auto‑downloads. pip installs the listed requirements, then three sed commands force local model loading, fix case‑sensitivity, and strip a problematic style attribute.

Finally, installing Pinggy opens a tunnel that maps localhost:7860 to a public URL, letting any browser reach the UI. Running python face_swap_ui.py launches the server; image swaps complete in a few seconds on CPU, making the setup perfect for demos, proof‑of‑concepts, or classroom labs. Future tweaks could add video or batch processing.