fix: add missing logging import and fix invalid get_one_face call in face_swapper#1730
Open
JiayuuWang wants to merge 1 commit intohacksider:mainfrom
Open
Conversation
- Add missing `import logging` that caused a NameError when the models directory could not be created in `pre_check()`. - Fix `get_one_face(processed_frame, detected_faces)` call in the live stream fallback path which incorrectly passed two arguments to a one-argument function. Replace with an inline min() over already- detected faces to match the original intent without a redundant detection pass.
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes two runtime errors in the face swapper: adds the missing logging import used in pre_check error handling, and replaces an invalid two-argument get_one_face call in the live-stream fallback path with direct selection from already-detected faces. Sequence diagram for updated fallback face selection in process_frame_v2sequenceDiagram
actor LiveUser
participant VideoStream
participant FaceSwapper as process_frame_v2
participant FaceDetector as detect_faces
LiveUser ->> VideoStream: Provide_frame()
VideoStream ->> FaceSwapper: process_frame_v2(temp_frame)
FaceSwapper ->> FaceDetector: detect_faces(processed_frame)
FaceDetector -->> FaceSwapper: detected_faces
alt map_faces_provided
FaceSwapper ->> FaceSwapper: build_source_target_pairs_with_mapping(detected_faces)
else fallback_simple_mode
FaceSwapper ->> FaceSwapper: source_face = default_source_face()
FaceSwapper ->> FaceSwapper: target_face = min(detected_faces, key=bbox_left)
FaceSwapper ->> FaceSwapper: append(source_face, target_face) to source_target_pairs
end
FaceSwapper -->> VideoStream: swapped_frame
VideoStream -->> LiveUser: Display(swapped_frame)
Flow diagram for pre_check directory creation with loggingflowchart TD
A[Start pre_check] --> B[Check models_directory exists]
B -->|Exists| C[Continue initialization]
B -->|Missing| D[Call os.makedirs on models_directory]
D --> E{os.makedirs successful?}
E -->|Yes| C
E -->|OSError raised| F[logging.error with exception details]
F --> G[Propagate or handle error appropriately]
C --> H[End pre_check]
G --> H
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider extracting the face-selection logic (currently duplicated from get_one_face via min(detected_faces, key=lambda x: x.bbox[0])) into a shared helper so any future changes to the selection criteria only need to be updated in one place.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the face-selection logic (currently duplicated from get_one_face via min(detected_faces, key=lambda x: x.bbox[0])) into a shared helper so any future changes to the selection criteria only need to be updated in one place.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two bugs in
modules/processors/frame/face_swapper.py:Bug 1 — Missing
loggingimport causesNameErrorIn
pre_check(), ifos.makedirs()raises anOSError(e.g. permission denied), the code callslogging.error(...)butloggingwas never imported. This triggers a secondaryNameError: name 'logging' is not defined, masking the original error and making it very hard to diagnose.Fix: add
import loggingto the imports.Bug 2 —
get_one_facecalled with two argumentsIn the live-stream fallback path of
process_frame_v2(line ~521):get_one_faceonly accepts one argument (frame), so this raises aTypeErrorat runtime. Faces have already been detected intodetected_facesat this point, so there's no need to call the analyser again. The fix reuses the already-detected list with the same selection logic (minbybbox[0]) thatget_one_faceuses internally, avoiding both the crash and a redundant detection pass.Test plan
--map-facesomitted (simple mode), to exercise the fallback path inprocess_frame_v2.TypeErroris raised when a face is detected in the live feed.NameError.🤖 Generated with Claude Code
Summary by Sourcery
Fix runtime errors in the face swapper fallback path and improve error logging for directory creation failures.
Bug Fixes: