From b7d834b87daab6916831340f660a546f4ed69135 Mon Sep 17 00:00:00 2001 From: fabasoad Date: Sat, 4 Jan 2025 01:02:49 +0900 Subject: [PATCH] Debug 10 --- action.yml | 5 +++++ src/providers/cloudmersive.sh | 10 ++++++++++ src/providers/picpurify.sh | 9 +++++++++ src/providers/sightengine.sh | 9 +++++++++ 4 files changed, 33 insertions(+) diff --git a/action.yml b/action.yml index 8635116..52c43ff 100644 --- a/action.yml +++ b/action.yml @@ -59,6 +59,7 @@ runs: - name: Classify files if: ${{ steps.changed-files.outputs.any_changed == 'true' }} + id: classify-files env: INPUT_PROVIDER: ${{ inputs.provider }} INPUT_API_KEY: ${{ inputs.api-key }} @@ -67,3 +68,7 @@ runs: "${{ steps.changed-files.outputs.all_changed_files }}" \ "${INPUT_API_KEY}" shell: sh + + - name: Print scores + run: echo "${{ steps.classify-files.outputs.scores }}" + shell: sh diff --git a/src/providers/cloudmersive.sh b/src/providers/cloudmersive.sh index 67f8758..2bb5f9c 100755 --- a/src/providers/cloudmersive.sh +++ b/src/providers/cloudmersive.sh @@ -12,6 +12,7 @@ main() { files="${1}" api_key="${2}" + result="[]" for file_path in ${files}; do log_debug "Classifying ${file_path}..." response=$(curl -sL \ @@ -20,13 +21,22 @@ main() { --header "Apikey: ${api_key}" \ --form "imageFile=@${file_path}") if [ "$(echo "${response}" | jq -r '.Successful')" = "true" ]; then + # Getting score score=$(echo "${response}" | jq -r '.Score') + # Build object for the output + obj="$(jq -n \ + --arg f "${file_path}" \ + --arg s "${score}" \ + '{file: $f, score: $s | tonumber}')" + # Add object to the resulting array + result=$(echo "${result}" | jq --argjson obj "${obj}" '. += [$obj]') log_info "Classified ${file_path} with score ${score}" else msg="There was a problem during ${file_path} file classification." log_warning "${msg}" fi done + echo "scores=${result}" >> "$GITHUB_OUTPUT" } main "$@" diff --git a/src/providers/picpurify.sh b/src/providers/picpurify.sh index 2a1275f..6118b75 100755 --- a/src/providers/picpurify.sh +++ b/src/providers/picpurify.sh @@ -20,7 +20,15 @@ main() { -F "task=porn_moderation,suggestive_nudity_moderation" \ -F "file_image=@${file_path}") if [ "$(echo "${response}" | jq -r '.status')" = "success" ]; then + # Getting score score=$(echo "${response}" | jq -r '.confidence_score_decision') + # Build object for the output + obj="$(jq -n \ + --arg f "${file_path}" \ + --arg s "${score}" \ + '{file: $f, score: $s | tonumber}')" + # Add object to the resulting array + result=$(echo "${result}" | jq --argjson obj "${obj}" '. += [$obj]') log_info "Classified ${file_path} with score ${score}" else msg="There was a problem during ${file_path} file classification." @@ -30,6 +38,7 @@ main() { log_warning "${msg}" fi done + echo "scores=${result}" >> "$GITHUB_OUTPUT" } main "$@" diff --git a/src/providers/sightengine.sh b/src/providers/sightengine.sh index 8b5647e..c7a5b64 100755 --- a/src/providers/sightengine.sh +++ b/src/providers/sightengine.sh @@ -22,7 +22,15 @@ main() { -F "api_user=${api_user}" \ -F "api_secret=${api_secret}") if [ "$(echo "${response}" | jq -r '.status')" = "success" ]; then + # Getting maximum score score=$(echo "${response}" | jq -r '.nudity | [.sexual_activity, .sexual_display, .erotica] | max') + # Build object for the output + obj="$(jq -n \ + --arg f "${file_path}" \ + --arg s "${score}" \ + '{file: $f, score: $s | tonumber}')" + # Add object to the resulting array + result=$(echo "${result}" | jq --argjson obj "${obj}" '. += [$obj]') log_info "Classified ${file_path} with score ${score}" else msg="There was a problem during ${file_path} file classification." @@ -32,6 +40,7 @@ main() { log_warning "${msg}" fi done + echo "scores=${result}" >> "$GITHUB_OUTPUT" } main "$@"