Skip to content

Commit

Permalink
If a caption is returned but the confidence score is lower than our t…
Browse files Browse the repository at this point in the history
…hreshold, output an error message instead of just discarding silently. Ensure the caption we save has the first letter uppercased. Ensure the values we want exist before using them
  • Loading branch information
dkotter committed Nov 26, 2024
1 parent 52087fe commit e2348de
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions includes/Classifai/Providers/Azure/ComputerVision.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,13 @@ public function generate_alt_tags( string $image_url, int $attachment_id ) {
$settings = $feature->get_settings( static::ID );
$threshold = $settings['descriptive_confidence_threshold'];

// Check the first caption to see if it passes the threshold.
if ( $caption['confidence'] * 100 > $threshold ) {
$rtn = $caption['text'];
// Check the caption to see if it passes the threshold.
if ( isset( $caption['confidence'] ) && $caption['confidence'] * 100 > $threshold ) {
$rtn = ucfirst( $caption['text'] ?? '' );
} else {
/* translators: 1: Confidence score, 2: Threshold setting */
$rtn = new WP_Error( 'threshold', sprintf( esc_html__( 'Caption confidence score is %1$d%% which is lower than your threshold setting of %2$d%%', 'classifai' ), $caption['confidence'] * 100, $threshold ) );

/**
* Fires if there were no captions returned.
*
Expand Down

0 comments on commit e2348de

Please sign in to comment.