Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
adjust backend docker deps and scipy version req
Browse files Browse the repository at this point in the history
  • Loading branch information
cainky committed Sep 23, 2023
1 parent d245634 commit e1f7ec3
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ A simple GUI app to synchronize recorded audio with video lip movements using th
- In the root project directory, run
```bash
docker-compose build
docker-compose up
```


Expand Down
3 changes: 2 additions & 1 deletion backend/docker/Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ FROM pytorch/pytorch:1.8.1-cuda11.1-cudnn8-runtime
WORKDIR /backend

# Install system dependencies
RUN apt-get update && apt-get install -y git wget && \
RUN apt-get update && apt-get install -y git wget libgl1-mesa-glx && \
rm -rf /var/lib/apt/lists/*


# Install backend dependencies
RUN pip install poetry

Expand Down
5 changes: 4 additions & 1 deletion backend/docker/download_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import gdown

base_directory = "/backend/wav2lip-hq/"
checkpoints_directory = base_directory + "checkpoints/"

urls = {
"wav2lip_gan.pth": "10Iu05Modfti3pDbxCFPnofmfVlbkvrCm",
"face_segmentation.pth": "154JgKpzCPW82qINcVieuPH3fZ2e0P812",
Expand All @@ -8,6 +11,6 @@

for name, id in urls.items():
url = f"https://drive.google.com/uc?id={id}"
output = f"checkpoints/{name}"
output = checkpoints_directory + name
gdown.download(url, output, quiet=False)
print(f"Loaded {name}")
89 changes: 88 additions & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ python = ">=3.8, <=3.13"
flask = "^2.3.3"
flask-cors = "^4.0.0"
ffmpeg = "^1.4"
numpy = ">=1.19.5, <1.27.0"
scipy = "^1.7"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
2 changes: 1 addition & 1 deletion backend/services/merge_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def merge_audio_video(audio_file, video_file):
)
except Exception as e:
clean_files(audio_path, video_path)
raise Exception("Output video not found after processing. Error: " + str(e))
raise Exception("Error: " + str(e))

return output_path
10 changes: 6 additions & 4 deletions backend/services/wav2lip_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ def run_command(cmd, workdir=None):
cmd, text=True, cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if result.returncode != 0:
raise Exception(
f"Command {cmd[0]} failed with return code {result.returncode}."
)
error_details = f"Command '{' '.join(cmd)}' failed with return code {result.returncode}. "
error_details += f"STDOUT: {result.stdout} "
error_details += f"STDERR: {result.stderr}"
raise Exception(error_details)
return result



def convert_webm_to_wav(input_path, output_path):
cmd = ["ffmpeg", "-y", "-i", input_path, output_path]
run_command(cmd)
Expand Down Expand Up @@ -71,6 +73,6 @@ def run_wav2lip_inference(face_path, audio_path, outfile_path):

if not os.path.exists(outfile_path):
error_msg = result.stderr if result.stderr else result.stdout
raise Exception(f"Output video not found after processing. Error: {error_msg}")
raise Exception(f"Error: {error_msg}")

return outfile_path
2 changes: 1 addition & 1 deletion backend/tests/services/test_merge_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_merge_audio_video_failure(self, mock_run, mock_remove, mock_exists):
mock_run.return_value = MagicMock(returncode=1, stderr="Error in Wav2Lip")

with self.assertRaisesRegex(
Exception, "Output video not found after processing"
Exception, "Error:"
):
merge_service.merge_audio_video(
self.sample_audio_file, self.sample_video_file
Expand Down
7 changes: 4 additions & 3 deletions backend/tests/services/test_wav2lip_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ def test_wav2lip_inference_processing_error(self, mock_run, mock_exists):

with self.assertRaises(Exception) as context:
run_wav2lip_inference(self.face, self.audio, self.outfile)

self.assertTrue(str(context.exception).startswith(f"Command 'ffmpeg -y -i test_audio.webm test_audio.wav' failed with return code 1."))
self.assertTrue("Error in Wav2Lip" in str(context.exception))


self.assertTrue(
"Command ffmpeg failed with return code 1." in str(context.exception)
)

@patch("os.path.exists", return_value=True)
@patch(
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_merge_disallowed_file_extensions(self):
self.assertEqual(response.json["error"], "File type not allowed")

def test_merge_error_during_process(self):
error_msg_prefix = "Output video not found after processing."
error_msg_prefix = "Error:"

with patch(
"services.merge_service.merge_audio_video",
Expand Down
1 change: 1 addition & 0 deletions frontend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BACKEND_URL=http://localhost:5000
2 changes: 1 addition & 1 deletion frontend/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ server {
}

location /api/ {
proxy_pass http://lipsync-backend:5000;
proxy_pass http://backend:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down

0 comments on commit e1f7ec3

Please sign in to comment.