Skip to content

Commit 96ad912

Browse files
author
w4hns1nn
committed
fixing a small bug with add_face and the swap endpoint
1 parent d334ca2 commit 96ad912

6 files changed

Lines changed: 110 additions & 2 deletions

File tree

apipod-deploy/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM python:3.8-slim
2+
3+
SHELL ["/bin/bash", "-c"]
4+
5+
# Install system dependencies together with optional extras.
6+
# Always install gcc for reliability; some ML packages still need compilation from source.
7+
# Others we detect automatically based on the deployment flags.
8+
RUN apt-get update && apt-get install -y \
9+
ffmpeg \
10+
gcc g++ \
11+
libcudnn9-cuda-12 \
12+
libcudnn9-dev-cuda-12 \
13+
&& apt-get clean
14+
# Ensure CUDA and cuDNN libraries are in the library path
15+
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"
16+
17+
# Set the working directory
18+
WORKDIR /
19+
20+
# Install Python dependencies
21+
RUN pip install --upgrade pip
22+
RUN pip install runpod>=1.7.7 && \
23+
pip install . --no-cache
24+
25+
# Configure APIPod for RunPod Serverless
26+
ENV APIPOD_BACKEND="runpod"
27+
ENV APIPOD_DEPLOYMENT="serverless"
28+
29+
ARG port=8080
30+
ENV APIPOD_PORT=$port
31+
EXPOSE $port
32+
ENV APIPOD_HOST="0.0.0.0"
33+
34+
# Set the entrypoint
35+
CMD ["uvicorn", "face2face\server:app", "--host", "0.0.0.0", "--port", "8000"]

apipod-deploy/apipod.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"entrypoint": "face2face\\server.py",
3+
"title": "Face2Face",
4+
"python_version": "3.8",
5+
"pytorch": false,
6+
"tensorflow": false,
7+
"onnx": "1.23.0",
8+
"transformers": false,
9+
"diffusers": false,
10+
"cuda": false,
11+
"system_packages": [],
12+
"model_files": [
13+
"face2face\\models\\face_occluder.onnx",
14+
"face2face\\models\\face_enhancer\\gfpgan_1.4.onnx",
15+
"face2face\\models\\face_enhancer\\gpen_bfr_1024.onnx",
16+
"face2face\\models\\face_enhancer\\gpen_bfr_2048.onnx",
17+
"face2face\\models\\face_enhancer\\gpen_bfr_256.onnx",
18+
"face2face\\models\\face_enhancer\\gpen_bfr_512.onnx",
19+
"face2face\\models\\insightface\\inswapper_128.onnx",
20+
"face2face\\models\\insightface\\buffalo_l\\1k3d68.onnx",
21+
"face2face\\models\\insightface\\buffalo_l\\2d106det.onnx",
22+
"face2face\\models\\insightface\\buffalo_l\\det_10g.onnx",
23+
"face2face\\models\\insightface\\buffalo_l\\genderage.onnx",
24+
"face2face\\models\\insightface\\buffalo_l\\w600k_r50.onnx"
25+
],
26+
"has_env_file": false
27+
}

apipod.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"entrypoint": "face2face\\server.py",
3+
"title": "Face2Face",
4+
"python_version": "3.8",
5+
"pytorch": false,
6+
"tensorflow": false,
7+
"onnx": "1.23.0",
8+
"transformers": false,
9+
"diffusers": false,
10+
"cuda": false,
11+
"system_packages": [],
12+
"model_files": [
13+
"face2face\\models\\face_occluder.onnx",
14+
"face2face\\models\\face_enhancer\\gfpgan_1.4.onnx",
15+
"face2face\\models\\face_enhancer\\gpen_bfr_1024.onnx",
16+
"face2face\\models\\face_enhancer\\gpen_bfr_2048.onnx",
17+
"face2face\\models\\face_enhancer\\gpen_bfr_256.onnx",
18+
"face2face\\models\\face_enhancer\\gpen_bfr_512.onnx",
19+
"face2face\\models\\insightface\\inswapper_128.onnx",
20+
"face2face\\models\\insightface\\buffalo_l\\1k3d68.onnx",
21+
"face2face\\models\\insightface\\buffalo_l\\2d106det.onnx",
22+
"face2face\\models\\insightface\\buffalo_l\\det_10g.onnx",
23+
"face2face\\models\\insightface\\buffalo_l\\genderage.onnx",
24+
"face2face\\models\\insightface\\buffalo_l\\w600k_r50.onnx"
25+
],
26+
"has_env_file": false
27+
}

face2face/core/face2face.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def swap(
116116

117117
# TODO: the fucking faces in dict is a shit with swapping by pairs (with recognition)
118118
# Needs to be fixed.
119-
if faces is not None and not isinstance(faces, dict):
119+
if faces is not None and isinstance(faces, dict):
120120
faces = list(self.get_faces(faces).values())
121121

122122
# read all the provided media

face2face/server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import face2face
1010
from face2face.core.face2face import Face2Face
1111
from media_toolkit.utils.generator_wrapper import SimpleGeneratorWrapper
12+
from face2face.core.mixins._face_embedding import FileWriteableFace
1213

1314
from face2face.settings import ALLOW_EMBEDDING_SAVE_ON_SERVER
1415

@@ -78,13 +79,19 @@ def add_face(
7879
faces = f2f.add_face(face_name=face_name, media=image, save=save)
7980

8081
if isinstance(faces, dict):
82+
faces = {
83+
face_name: FileWriteableFace(face)
84+
for face_name, face in faces.items()
85+
}
86+
8187
return MediaList([
8288
MediaFile(file_name=f"{face_name}.npy").from_bytesio(face.to_bytes_io())
8389
for face_name, face in faces.items()
8490
])
8591

8692
if isinstance(faces, tuple):
87-
return MediaFile(file_name=f"{face_name}.npy").from_bytesio(faces[1].to_bytes_io())
93+
face = FileWriteableFace(faces[1]).to_bytes_io()
94+
return MediaFile(file_name=f"{face_name}.npy").from_bytesio(face)
8895

8996

9097
@app.endpoint("/swap")

test_api_pod.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# debug_apipod.py (place in face2face root directory)
2+
import sys
3+
import os
4+
5+
# Add apipod to path
6+
sys.path.insert(0, r'A:\projects\apipod')
7+
8+
# Import and run the CLI
9+
from apipod.cli import main
10+
11+
if __name__ == "__main__":
12+
main()

0 commit comments

Comments
 (0)