Skip to content

Instantly share code, notes, and snippets.

@AbeEstrada
Last active October 14, 2024 15:29
Show Gist options
  • Save AbeEstrada/feaac3f86d4ec7f76cc96bd373575ae4 to your computer and use it in GitHub Desktop.
Save AbeEstrada/feaac3f86d4ec7f76cc96bd373575ae4 to your computer and use it in GitHub Desktop.
#!/bin/zsh
usage() {
echo "https://github.com/facefusion/facefusion"
echo "Usage: $0 -s source_image -t target_image [-r reference_face_position] [-e]"
echo " -s: Path to the source image"
echo " -t: Path to the target image"
echo " -r: Reference face position (default: 0)"
echo " -e: Toggle to remove the face enhancer (optional)"
exit 1
}
REFERENCE_FACE_POSITION=0
FACE_ENHANCER=true
while getopts "s:t:r:e" opt; do
case $opt in
s) SOURCE_IMAGE=$OPTARG ;;
t) TARGET_IMAGE=$OPTARG ;;
r) REFERENCE_FACE_POSITION=$OPTARG ;;
e) FACE_ENHANCER=false ;;
*) usage ;;
esac
done
if [ -z "$SOURCE_IMAGE" ] || [ -z "$TARGET_IMAGE" ]; then
usage
fi
TARGET_EXTENSION="${TARGET_IMAGE##*.}"
OUTPUT_FILENAME=$(basename "$TARGET_IMAGE")
TIMESTAMP=$(date +%s)
OUTPUT_FILE="~/Downloads/${OUTPUT_FILENAME%.*}_$TIMESTAMP.$TARGET_EXTENSION"
CMD="python facefusion.py headless-run --processors face_swapper"
if $FACE_ENHANCER; then
CMD="$CMD face_enhancer --face-enhancer-blend 99"
fi
CMD="$CMD --output-image-quality 99 --reference-face-position $REFERENCE_FACE_POSITION -s $SOURCE_IMAGE -t $TARGET_IMAGE -o $OUTPUT_FILE"
echo "\e[0;34mRunning command: \e[0m$CMD"
eval $CMD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment