-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next (Sourcery refactored) #3
base: next
Are you sure you want to change the base?
Conversation
if frame_hash in FACES_CACHE: | ||
return FACES_CACHE[frame_hash] | ||
return None | ||
return FACES_CACHE[frame_hash] if frame_hash in FACES_CACHE else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_faces_cache
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
frame_hash = create_frame_hash(frame) | ||
if frame_hash: | ||
if frame_hash := create_frame_hash(frame): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function set_faces_cache
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
subprocess.call([ 'pip', 'install', '-r', 'requirements.txt', '--extra-index-url', 'https://download.pytorch.org/whl/' + torch_wheel ]) | ||
subprocess.call( | ||
[ | ||
'pip', | ||
'install', | ||
'-r', | ||
'requirements.txt', | ||
'--extra-index-url', | ||
f'https://download.pytorch.org/whl/{torch_wheel}', | ||
] | ||
) | ||
subprocess.call([ 'pip', 'uninstall', 'onnxruntime', onnxruntime_name, '-y' ]) | ||
subprocess.call([ 'pip', 'install', onnxruntime_name + '==' + onnxruntime_version ]) | ||
subprocess.call( | ||
['pip', 'install', f'{onnxruntime_name}=={onnxruntime_version}'] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function run
refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
)
commands = [ 'ffmpeg', '-hide_banner', '-loglevel', 'error' ] | ||
commands.extend(args) | ||
commands = ['ffmpeg', '-hide_banner', '-loglevel', 'error', *args] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function run_ffmpeg
refactored with the following changes:
- Merge extend into list declaration (
merge-list-extend
)
commands = [ 'ffmpeg', '-hide_banner', '-loglevel', 'error' ] | ||
commands.extend(args) | ||
commands = ['ffmpeg', '-hide_banner', '-loglevel', 'error', *args] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function open_ffmpeg
refactored with the following changes:
- Merge extend into list declaration (
merge-list-extend
)
if model_type == 'blendface': | ||
frame_processor_inputs[frame_processor_input.name] = prepare_source_frame(source_face) | ||
else: | ||
frame_processor_inputs[frame_processor_input.name] = prepare_source_embedding(source_face) | ||
if frame_processor_input.name == 'target': | ||
frame_processor_inputs[frame_processor_input.name] = ( | ||
prepare_source_frame(source_face) | ||
if model_type == 'blendface' | ||
else prepare_source_embedding(source_face) | ||
) | ||
elif frame_processor_input.name == 'target': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function swap_face
refactored with the following changes:
- Simplify conditional into switch-like form [×3] (
switch
) - Replace if statement with if expression (
assign-if-exp
)
similar_faces = find_similar_faces(temp_frame, reference_face, facefusion.globals.reference_face_distance) | ||
if similar_faces: | ||
if similar_faces := find_similar_faces( | ||
temp_frame, reference_face, facefusion.globals.reference_face_distance | ||
): | ||
for similar_face in similar_faces: | ||
temp_frame = swap_face(source_face, similar_face, temp_frame) | ||
if 'one' in facefusion.globals.face_selector_mode: | ||
target_face = get_one_face(temp_frame) | ||
if target_face: | ||
if target_face := get_one_face(temp_frame): | ||
temp_frame = swap_face(source_face, target_face, temp_frame) | ||
if 'many' in facefusion.globals.face_selector_mode: | ||
many_faces = get_many_faces(temp_frame) | ||
if many_faces: | ||
if many_faces := get_many_faces(temp_frame): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function process_frame
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×3] (
use-named-expression
)
component = get_ui_component(component_name) | ||
if component: | ||
if component := get_ui_component(component_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function listen
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×4] (
use-named-expression
)
source_image = get_ui_component('source_image') | ||
if source_image: | ||
if source_image := get_ui_component('source_image'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function listen
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
commands.extend([ '-f', 'v4l2', '/dev/' + device_name ]) | ||
commands.extend(['-f', 'v4l2', f'/dev/{device_name}']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function open_stream
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
Pull Request #2 refactored by Sourcery.
Since the original Pull Request was opened as a fork in a contributor's
repository, we are unable to create a Pull Request branching from it.
To incorporate these changes, you can either:
Merge this Pull Request instead of the original, or
Ask your contributor to locally incorporate these commits and push them to
the original Pull Request
Incorporate changes via command line
NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Help us improve this pull request!