diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php
index 9acdf9564..60f51ebc2 100644
--- a/includes/Classifai/Admin/Notifications.php
+++ b/includes/Classifai/Admin/Notifications.php
@@ -117,8 +117,8 @@ public function render_activation_notice() {
/**
* Display a dismissable admin notice when a threshold may need updating.
*
- * We used to recommend thresholds between 70-75% but in the latest
- * version of the AI Vision API, seems 55% is a better threshold.
+ * We used to recommend thresholds between 50-55% but in the latest
+ * version of the AI Vision API, seems 70% is a better threshold.
*/
public function thresholds_update_notice() {
$features = [
@@ -144,7 +144,7 @@ public function thresholds_update_notice() {
switch ( $feature_instance::ID ) {
case DescriptiveTextGenerator::ID:
$key = 'descriptive_confidence_threshold';
- $message = __( 'The previous recommended threshold for descriptive text generation was 75% but we find better results now at around 55%.', 'classifai' );
+ $message = __( 'The previous recommended threshold for descriptive text generation was 55% but we find better results now at around 70%.', 'classifai' );
break;
}
@@ -153,8 +153,8 @@ public function thresholds_update_notice() {
continue;
}
- // Don't show the notice if the threshold is already at 55% or lower.
- if ( $key && isset( $settings[ $key ] ) && $settings[ $key ] <= 55 ) {
+ // Don't show the notice if the threshold is already at 70% or higher.
+ if ( $key && isset( $settings[ $key ] ) && $settings[ $key ] >= 70 ) {
continue;
}
?>
@@ -165,9 +165,9 @@ public function thresholds_update_notice() {
echo wp_kses_post(
sprintf(
// translators: %1$s: Feature specific message; %2$s: URL to Feature settings.
- __( 'ClassifAI has updated to the v3.2 of the Azure AI Vision API. %1$s Click here to adjust those settings.', 'classifai' ),
+ __( 'ClassifAI has updated to the v4.0 of the Azure AI Vision API. %1$s Click here to adjust those settings.', 'classifai' ),
esc_html( $message ),
- esc_url( admin_url( "tools.php?page=classifai&tab=image_processing&feature=$name" ) )
+ esc_url( admin_url( "tools.php?page=classifai#/image_processing/$name" ) )
)
);
?>
diff --git a/includes/Classifai/Helpers.php b/includes/Classifai/Helpers.php
index df93c53c1..ca233973a 100644
--- a/includes/Classifai/Helpers.php
+++ b/includes/Classifai/Helpers.php
@@ -152,7 +152,7 @@ function computer_vision_max_filesize(): int {
*
* @return {int} Filtered filesize in bytes.
*/
- return apply_filters( 'classifai_computer_vision_max_filesize', 4 * MB_IN_BYTES ); // 4MB default.
+ return apply_filters( 'classifai_computer_vision_max_filesize', 20 * MB_IN_BYTES ); // 20MB default.
}
/**
diff --git a/includes/Classifai/Providers/Azure/ComputerVision.php b/includes/Classifai/Providers/Azure/ComputerVision.php
index 961e05c4a..c8be843ca 100644
--- a/includes/Classifai/Providers/Azure/ComputerVision.php
+++ b/includes/Classifai/Providers/Azure/ComputerVision.php
@@ -15,7 +15,7 @@
use WP_Error;
use function Classifai\computer_vision_max_filesize;
-use function Classifai\get_largest_acceptable_image_url;
+use function Classifai\get_largest_size_and_dimensions_image_url;
use function Classifai\get_modified_image_source_url;
class ComputerVision extends Provider {
@@ -25,7 +25,23 @@ class ComputerVision extends Provider {
/**
* @var string URL fragment to the analyze API endpoint
*/
- protected $analyze_url = 'vision/v3.2/analyze';
+ protected $analyze_url = 'computervision/imageanalysis:analyze?api-version=2024-02-01';
+
+ /**
+ * Image types to process.
+ *
+ * @var array
+ */
+ private $image_types_to_process = [
+ 'bmp',
+ 'gif',
+ 'jpeg',
+ 'png',
+ 'webp',
+ 'ico',
+ 'tiff',
+ 'mpo',
+ ];
/**
* ComputerVision constructor.
@@ -115,7 +131,7 @@ public function add_descriptive_text_generation_fields() {
'min' => 1,
'step' => 1,
'default_value' => $settings['descriptive_confidence_threshold'],
- 'description' => esc_html__( 'Minimum confidence score for automatically added generated text, numeric value from 0-100. Recommended to be set to at least 55.', 'classifai' ),
+ 'description' => esc_html__( 'Minimum confidence score for automatically added generated text, numeric value from 0-100. Recommended to be set to at least 70.', 'classifai' ),
'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this.
]
);
@@ -164,7 +180,7 @@ public function get_default_provider_settings(): array {
return array_merge(
$common_settings,
[
- 'descriptive_confidence_threshold' => 55,
+ 'descriptive_confidence_threshold' => 70,
]
);
@@ -377,23 +393,17 @@ public function smart_crop_image( array $metadata, int $attachment_id ) {
*
* @since 1.6.0
*
- * @param array $metadata Attachment metadata.
- * @param int $attachment_id Attachment ID.
+ * @param string $image_url URL of image to process.
+ * @param int $attachment_id Attachment ID.
* @return string|WP_Error
*/
- public function ocr_processing( array $metadata = [], int $attachment_id = 0 ) {
+ public function ocr_processing( string $image_url, int $attachment_id = 0 ) {
if ( ! wp_attachment_is_image( $attachment_id ) ) {
return new WP_Error( 'invalid', esc_html__( 'This attachment can\'t be processed.', 'classifai' ) );
}
- $feature = new ImageTextExtraction();
- $settings = $feature->get_settings( static::ID );
-
- if ( ! is_array( $metadata ) || ! is_array( $settings ) ) {
- return new WP_Error( 'invalid', esc_html__( 'Invalid data found. Please check your settings and try again.', 'classifai' ) );
- }
-
- $should_ocr_scan = $feature->is_feature_enabled();
+ $feature = new ImageTextExtraction();
+ $rtn = '';
/**
* Filters whether to run OCR scanning on the current image.
@@ -401,25 +411,61 @@ public function ocr_processing( array $metadata = [], int $attachment_id = 0 ) {
* @since 1.6.0
* @hook classifai_should_ocr_scan_image
*
- * @param {bool} $should_ocr_scan Whether to run OCR scanning. The default value is set in ComputerVision settings.
- * @param {array} $metadata Image metadata.
- * @param {int} $attachment_id The attachment ID.
+ * @param {bool} $should_scan Whether to run OCR scanning. Defaults to feature being enabled.
+ * @param {string} $image_url URL of image to process.
+ * @param {int} $attachment_id The attachment ID.
*
* @return {bool} Whether to run OCR scanning.
*/
- if ( ! apply_filters( 'classifai_should_ocr_scan_image', $should_ocr_scan, $metadata, $attachment_id ) ) {
+ if ( ! apply_filters( 'classifai_should_ocr_scan_image', $feature->is_feature_enabled(), $image_url, $attachment_id ) ) {
return '';
}
- $image_url = wp_get_attachment_url( $attachment_id );
- $scan = $this->scan_image( $image_url, $feature );
+ $details = $this->scan_image( $image_url, $feature );
+
+ if ( is_wp_error( $details ) ) {
+ return $details;
+ }
+
+ set_transient( 'classifai_azure_computer_vision_image_text_extraction_latest_response', $details, DAY_IN_SECONDS * 30 );
- $ocr = new OCR( $settings, $scan );
- $response = $ocr->generate_ocr_data( $metadata, $attachment_id );
+ if ( isset( $details->readResult ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
+ $text = [];
+
+ // Iterate down the chain to find the text we want.
+ foreach ( $details->readResult as $result ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
+ foreach ( $result as $block ) {
+ foreach ( $block as $lines ) {
+ foreach ( $lines as $line ) {
+ if ( isset( $line->text ) ) {
+ $text[] = $line->text;
+ }
+ }
+ }
+ }
+ }
- set_transient( 'classifai_azure_computer_vision_image_text_extraction_latest_response', $scan, DAY_IN_SECONDS * 30 );
+ if ( ! empty( $text ) ) {
- return $response;
+ /**
+ * Filter the text returned from the API.
+ *
+ * @since 1.6.0
+ * @hook classifai_ocr_text
+ *
+ * @param {string} $text The returned text data.
+ * @param {object} $details The full scan results from the API.
+ *
+ * @return {string} The filtered text data.
+ */
+ $rtn = apply_filters( 'classifai_ocr_text', implode( ' ', $text ), $details );
+
+ // Save all the results for later
+ update_post_meta( $attachment_id, 'classifai_computer_vision_ocr', $details );
+ }
+ }
+
+ return $rtn;
}
/**
@@ -443,45 +489,48 @@ public function generate_alt_tags( string $image_url, int $attachment_id ) {
return $details;
}
- $captions = $details->description->captions ?? [];
+ $caption = isset( $details->captionResult ) ? (array) $details->captionResult : []; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
set_transient( 'classifai_azure_computer_vision_descriptive_text_latest_response', $details, DAY_IN_SECONDS * 30 );
/**
- * Filter the captions returned from the API.
+ * Filter the caption returned from the API.
*
* @since 1.4.0
* @hook classifai_computer_vision_captions
*
- * @param {array} $captions The returned caption data.
+ * @param {array} $caption The returned caption data.
*
* @return {array} The filtered caption data.
*/
- $captions = apply_filters( 'classifai_computer_vision_captions', $captions );
+ $caption = apply_filters( 'classifai_computer_vision_captions', $caption );
- // Process the returned captions to see if they pass the threshold.
- if ( is_array( $captions ) && ! empty( $captions ) ) {
+ // Process the returned caption to see if it passes the threshold.
+ if ( is_array( $caption ) && ! empty( $caption ) ) {
$settings = $feature->get_settings( static::ID );
$threshold = $settings['descriptive_confidence_threshold'];
- // Check the first caption to see if it passes the threshold.
- if ( $captions[0]->confidence * 100 > $threshold ) {
- $rtn = $captions[0]->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.
*
* @since 1.5.0
* @hook classifai_computer_vision_caption_failed
*
- * @param {array} $tags The caption data.
+ * @param {array} $caption The caption data.
* @param {int} $threshold The caption_threshold setting.
*/
- do_action( 'classifai_computer_vision_caption_failed', $captions, $threshold );
+ do_action( 'classifai_computer_vision_caption_failed', $caption, $threshold );
}
- // Save all the results for later.
- update_post_meta( $attachment_id, 'classifai_computer_vision_captions', $captions );
+ // Save full results for later.
+ update_post_meta( $attachment_id, 'classifai_computer_vision_captions', $caption );
}
return $rtn;
@@ -540,7 +589,7 @@ public function generate_image_tags( string $image_url, int $attachment_id ) {
return $details;
}
- $tags = $details->tags ?? [];
+ $tags = $details->tagsResult->values ?? []; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
set_transient( 'classifai_azure_computer_vision_image_tags_latest_response', $details, DAY_IN_SECONDS * 30 );
@@ -674,14 +723,18 @@ protected function prep_api_url( \Classifai\Features\Feature $feature = null ):
$api_features = [];
if ( $feature instanceof DescriptiveTextGenerator && $feature->is_feature_enabled() && ! empty( $feature->get_alt_text_settings() ) ) {
- $api_features[] = 'Description';
+ $api_features[] = 'caption';
}
if ( $feature instanceof ImageTagsGenerator && $feature->is_feature_enabled() ) {
- $api_features[] = 'Tags';
+ $api_features[] = 'tags';
}
- $endpoint = add_query_arg( 'visualFeatures', implode( ',', $api_features ), trailingslashit( $settings['endpoint_url'] ) . $this->analyze_url );
+ if ( $feature instanceof ImageTextExtraction && $feature->is_feature_enabled() ) {
+ $api_features[] = 'read';
+ }
+
+ $endpoint = add_query_arg( 'features', implode( ',', $api_features ), trailingslashit( $settings['endpoint_url'] ) . $this->analyze_url );
return $endpoint;
}
@@ -743,22 +796,36 @@ public function rest_endpoint_callback( $attachment_id, string $route_to_call =
return new WP_Error( 'invalid', esc_html__( 'No valid metadata found.', 'classifai' ) );
}
- switch ( $route_to_call ) {
- case 'ocr':
- return $this->ocr_processing( $metadata, $attachment_id );
+ if ( 'crop' === $route_to_call ) {
+ return $this->smart_crop_image( $metadata, $attachment_id );
+ }
+
+ // Check if the image is of a type we can process.
+ $mime_type = get_post_mime_type( $attachment_id );
+ $matched_extensions = explode( '|', array_search( $mime_type, wp_get_mime_types(), true ) );
+ $process = false;
- case 'crop':
- return $this->smart_crop_image( $metadata, $attachment_id );
+ foreach ( $matched_extensions as $ext ) {
+ if ( in_array( $ext, $this->image_types_to_process, true ) ) {
+ $process = true;
+ break;
+ }
+ }
+
+ if ( ! $process ) {
+ return new WP_Error( 'invalid', esc_html__( 'Image does not match a valid mime type.', 'classifai' ) );
}
$image_url = get_modified_image_source_url( $attachment_id );
if ( empty( $image_url ) || ! filter_var( $image_url, FILTER_VALIDATE_URL ) ) {
if ( isset( $metadata['sizes'] ) && is_array( $metadata['sizes'] ) ) {
- $image_url = get_largest_acceptable_image_url(
+ $image_url = get_largest_size_and_dimensions_image_url(
get_attached_file( $attachment_id ),
wp_get_attachment_url( $attachment_id ),
- $metadata['sizes'],
+ $metadata,
+ [ 50, 16000 ],
+ [ 50, 16000 ],
computer_vision_max_filesize()
);
} else {
@@ -767,13 +834,16 @@ public function rest_endpoint_callback( $attachment_id, string $route_to_call =
}
if ( empty( $image_url ) ) {
- return new WP_Error( 'error', esc_html__( 'Valid image size not found. Make sure the image is less than 4MB.', 'classifai' ) );
+ return new WP_Error( 'error', esc_html__( 'Image does not meet size requirements. Please ensure it is at least 50x50 but less than 16000x16000 and smaller than 20MB.', 'classifai' ) );
}
switch ( $route_to_call ) {
case 'descriptive_text':
return $this->generate_alt_tags( $image_url, $attachment_id );
+ case 'ocr':
+ return $this->ocr_processing( $image_url, $attachment_id );
+
case 'tags':
return $this->generate_image_tags( $image_url, $attachment_id );
}
diff --git a/includes/Classifai/Providers/Azure/OCR.php b/includes/Classifai/Providers/Azure/OCR.php
deleted file mode 100644
index 5ee7b70be..000000000
--- a/includes/Classifai/Providers/Azure/OCR.php
+++ /dev/null
@@ -1,323 +0,0 @@
-settings = $settings;
- $this->scan = $scan;
- }
-
- /**
- * Builds the API url.
- *
- * @since 1.6.0
- *
- * @return string
- */
- public function get_api_url(): string {
- return sprintf( '%s%s', trailingslashit( $this->settings['endpoint_url'] ), static::API_PATH );
- }
-
- /**
- * Returns whether OCR processing should be applied to the attachment
- *
- * @since 1.6.0
- *
- * @param int $attachment_id Attachment ID.
- * @return bool
- */
- public function should_process( int $attachment_id ): bool {
- $mime_type = get_post_mime_type( $attachment_id );
- $matched_extensions = explode( '|', array_search( $mime_type, wp_get_mime_types(), true ) );
- $process = false;
-
- /**
- * Filters the media types that should be processed
- *
- * @since 1.6.0
- * @hook classifai_ocr_approved_media_types
- *
- * @param {array} $media_types The media types to process.
- * @param {int} $attachment_id The attachment ID.
- *
- * @return {array} Filtered media types.
- */
- $approved_media_types = apply_filters( 'classifai_ocr_approved_media_types', $this->media_to_process, $attachment_id );
-
- foreach ( $matched_extensions as $ext ) {
- if ( in_array( $ext, $approved_media_types, true ) ) {
- $process = true;
- }
- }
-
- // If we have a proper image and a previous image scan, check
- // to see if we have proper tags set, with a high confidence
- if ( $process && $this->scan && ! empty( $this->scan->tags ) && is_array( $this->scan->tags ) ) {
-
- /**
- * Filters the tags we check for OCR processing
- *
- * @since 1.6.0
- * @hook classifai_ocr_tags
- *
- * @param {array} $tags Tags to look for. Default handwriting and text.
- * @param {int} $attachment_id The attachment ID.
- * @param {bool|object} $scan Previously run scan.
- *
- * @return {array} Filtered tags.
- */
- $tags = apply_filters( 'classifai_ocr_tags', [ 'handwriting', 'text' ], $attachment_id, $this->scan );
-
- /**
- * Filters the tag confidence level for OCR processing
- *
- * @since 1.6.0
- * @hook classifai_ocr_tag_confidence
- *
- * @param {int} $confidence The minimum confidence level. Default 90.
- * @param {int} $attachment_id The attachment ID.
- * @param {bool|object} $scan Previously run scan.
- *
- * @return {int} Confidence level.
- */
- $tag_confidence = apply_filters( 'classifai_ocr_tag_confidence', 90, $attachment_id, $this->scan );
-
- foreach ( $this->scan->tags as $tag ) {
- if ( in_array( $tag->name, $tags, true ) && $tag->confidence * 100 >= $tag_confidence ) {
- $process = true;
- break;
- }
- }
- }
-
- /**
- * Filters whether to run OCR processing on this media item
- *
- * @since 1.6.0
- * @hook classifai_ocr_should_process
- *
- * @param {bool} $process Whether to run OCR processing or not.
- * @param {int} $attachment_id The attachment ID.
- * @param {bool|object} $scan Previously run scan.
- *
- * @return {bool} Whether this attachment should have OCR processing.
- */
- return apply_filters( 'classifai_ocr_should_process', $process, $attachment_id, $this->scan );
- }
-
- /**
- * Get the OCR data
- *
- * @since 1.6.0
- *
- * @param array $metadata Attachment metadata.
- * @param integer $attachment_id Attachment ID.
- * @return string|WP_Error
- */
- public function generate_ocr_data( array $metadata, int $attachment_id ) {
- $rtn = '';
-
- if ( ! $this->should_process( $attachment_id ) ) {
- return new WP_Error( 'process_error', esc_html__( 'Image does not meet processing requirements.', 'classifai' ), $metadata );
- }
-
- $url = get_largest_size_and_dimensions_image_url(
- get_attached_file( $attachment_id ),
- wp_get_attachment_url( $attachment_id ),
- $metadata,
- [ 50, 4200 ],
- [ 50, 4200 ],
- computer_vision_max_filesize()
- );
-
- // If a properly sized image isn't found, return
- if ( ! $url ) {
- return new WP_Error( 'size_error', esc_html__( 'Image does not meet size requirements. Please ensure it is at least 50x50 but less than 4200x4200 and smaller than 4MB.', 'classifai' ), $metadata );
- }
-
- $scan = $this->process( $url );
-
- set_transient( 'classifai_azure_computer_vision_ocr_latest_response', $scan, DAY_IN_SECONDS * 30 );
-
- if ( ! is_wp_error( $scan ) && isset( $scan->regions ) ) {
- $text = [];
-
- // Iterate down the chain to find the text we want
- foreach ( $scan->regions as $region ) {
- foreach ( $region->lines as $lines ) {
- foreach ( $lines->words as $word ) {
- if ( isset( $word->text ) ) {
- $text[] = $word->text;
- }
- }
- }
- }
-
- if ( ! empty( $text ) ) {
-
- /**
- * Filter the text returned from the API.
- *
- * @since 1.6.0
- * @hook classifai_ocr_text
- *
- * @param {string} $text The returned text data.
- * @param {object} $scan The full scan results from the API.
- *
- * @return {string} The filtered text data.
- */
- $rtn = apply_filters( 'classifai_ocr_text', implode( ' ', $text ), $scan );
-
- // Save all the results for later
- update_post_meta( $attachment_id, 'classifai_computer_vision_ocr', $scan );
- }
- } else {
- $rtn = $scan;
- }
-
- return $rtn;
- }
-
- /**
- * Run OCR processing using the Azure API
- *
- * @since 1.6.0
- *
- * @param string $url Media URL.
- * @return object|WP_Error
- */
- public function process( string $url ) {
- // Check if valid authentication is in place.
- if ( empty( $this->settings ) || ( isset( $this->settings['authenticated'] ) && false === $this->settings['authenticated'] ) ) {
- return new WP_Error( 'auth', esc_html__( 'Please set up valid authentication with Azure.', 'classifai' ) );
- }
-
- $response = wp_remote_post(
- $this->get_api_url(),
- [
- 'body' => wp_json_encode(
- [
- 'url' => $url,
- ]
- ),
- 'headers' => [
- 'Content-Type' => 'application/json',
- 'Ocp-Apim-Subscription-Key' => $this->settings['api_key'],
- ],
- ]
- );
-
- /**
- * Fires after the request to the ocr endpoint has run.
- *
- * @since 1.6.0
- * @hook classifai_ocr_after_request
- *
- * @param {array|WP_Error} Response data or a WP_Error if the request failed.
- * @param {string} The attachment URL.
- */
- do_action( 'classifai_ocr_after_request', $response, $url );
-
- if ( ! is_wp_error( $response ) ) {
- $body = json_decode( wp_remote_retrieve_body( $response ) );
-
- if ( isset( $body->message ) ) {
- $error_message = $body->message;
- } elseif ( isset( $body->error->message ) ) {
- $error_message = $body->error->message;
- } else {
- $error_message = false;
- }
-
- if ( 200 !== wp_remote_retrieve_response_code( $response ) && $error_message ) {
- /**
- * Fires when the ocr API response did not succeed.
- *
- * @since 1.6.0
- * @hook classifai_ocr_unsuccessful_response
- *
- * @param {array|WP_Error} Response data or a WP_Error if the request failed.
- * @param {string} The attachment URL.
- */
- do_action( 'classifai_ocr_unsuccessful_response', $response, $url );
-
- $rtn = new WP_Error( $body->code ?? 'error', $error_message, $body );
- } else {
- $rtn = $body;
- }
- } else {
- $rtn = $response;
- }
-
- return $rtn;
- }
-}
diff --git a/src/js/settings/components/provider-settings/azure-ai-vision.js b/src/js/settings/components/provider-settings/azure-ai-vision.js
index f34a27e21..77957d154 100644
--- a/src/js/settings/components/provider-settings/azure-ai-vision.js
+++ b/src/js/settings/components/provider-settings/azure-ai-vision.js
@@ -78,7 +78,7 @@ export const AzureAIVisionSettings = ( { isConfigured = false } ) => {
@@ -87,7 +87,7 @@ export const AzureAIVisionSettings = ( { isConfigured = false } ) => {
type="number"
value={
providerSettings.descriptive_confidence_threshold ||
- 55
+ 70
}
onChange={ ( value ) =>
onChange( {
diff --git a/tests/Classifai/Azure/ComputerVisionTest.php b/tests/Classifai/Azure/ComputerVisionTest.php
index 1abb424e1..ed32d9398 100644
--- a/tests/Classifai/Azure/ComputerVisionTest.php
+++ b/tests/Classifai/Azure/ComputerVisionTest.php
@@ -42,7 +42,7 @@ public function test_get_debug_information() {
$this->assertEquals(
[
'Generate descriptive text' => '0, 0, 0',
- 'Confidence threshold' => 55,
+ 'Confidence threshold' => 70,
'Latest response:' => 'N/A',
],
$this->provider->get_debug_information(
diff --git a/tests/Classifai/Providers/Azure/ComputerVisionTest.php b/tests/Classifai/Providers/Azure/ComputerVisionTest.php
index e20a2e9c9..0b460795c 100644
--- a/tests/Classifai/Providers/Azure/ComputerVisionTest.php
+++ b/tests/Classifai/Providers/Azure/ComputerVisionTest.php
@@ -85,7 +85,7 @@ public function test_no_computer_vision_option_set() {
'endpoint_url' => '',
'api_key' => '',
'authenticated' => false,
- 'descriptive_confidence_threshold' => 55,
+ 'descriptive_confidence_threshold' => 70,
],
]
);
diff --git a/tests/cypress/plugins/functions.js b/tests/cypress/plugins/functions.js
index 014016904..fbb9d8fa3 100644
--- a/tests/cypress/plugins/functions.js
+++ b/tests/cypress/plugins/functions.js
@@ -3,7 +3,6 @@ import * as chatgptData from '../../test-plugin/chatgpt.json';
import * as chatgptCustomExcerptData from '../../test-plugin/chatgpt-custom-excerpt-prompt.json';
import * as chatgptCustomTitleData from '../../test-plugin/chatgpt-custom-title-prompt.json';
import * as dalleData from '../../test-plugin/dalle.json';
-import * as ocrData from '../../test-plugin/ocr.json';
import * as whisperData from '../../test-plugin/whisper.json';
import * as imageData from '../../test-plugin/image_analyze.json';
import * as pdfData from '../../test-plugin/pdf.json';
@@ -99,7 +98,7 @@ export const getWhisperData = () => {
*/
export const getOCRData = () => {
const words = [];
- ocrData.regions.forEach( ( el ) => {
+ imageData.readResult.blocks.forEach( ( el ) => {
el.lines.forEach( ( el2 ) => {
el2.words.forEach( ( el3 ) => {
words.push( el3.text );
@@ -116,10 +115,8 @@ export const getOCRData = () => {
*/
export const getImageData = () => {
const data = {
- altText: imageData.description.captions.filter(
- ( el ) => el.confidence > 0.75
- )[ 0 ].text,
- tags: imageData.tags
+ altText: imageData.captionResult.text,
+ tags: imageData.tagsResult.values
.filter( ( el ) => el.confidence > 0.7 )
.map( ( el ) => el.name ),
};
diff --git a/tests/test-plugin/e2e-test-plugin.php b/tests/test-plugin/e2e-test-plugin.php
index 6753215d3..3659f1ffd 100644
--- a/tests/test-plugin/e2e-test-plugin.php
+++ b/tests/test-plugin/e2e-test-plugin.php
@@ -80,10 +80,8 @@ function classifai_test_mock_http_requests( $preempt, $parsed_args, $url ) {
strpos( $url, 'https://e2e-test-azure-openai-embeddings.test/openai/deployments' ) !== false
) {
$response = file_get_contents( __DIR__ . '/embeddings.json' );
- } elseif ( strpos( $url, 'http://e2e-test-image-processing.test/vision/v3.2/analyze' ) !== false ) {
+ } elseif ( strpos( $url, 'http://e2e-test-image-processing.test/computervision/imageanalysis:analyze?api-version=2024-02-01' ) !== false ) {
$response = file_get_contents( __DIR__ . '/image_analyze.json' );
- } elseif ( strpos( $url, 'http://e2e-test-image-processing.test/vision/v3.2/ocr' ) !== false ) {
- $response = file_get_contents( __DIR__ . '/ocr.json' );
} elseif ( strpos( $url, 'http://e2e-test-image-processing.test/vision/v3.2/generateThumbnail' ) !== false ) {
$response = file_get_contents( __DIR__ . '../classifai/assets/img/icon256x256.png' );
} elseif ( strpos( $url, 'http://e2e-test-image-processing.test/pdf-read-result' ) !== false ) {
diff --git a/tests/test-plugin/image_analyze.json b/tests/test-plugin/image_analyze.json
index 5e0e58943..d2dbcb351 100644
--- a/tests/test-plugin/image_analyze.json
+++ b/tests/test-plugin/image_analyze.json
@@ -1,81 +1,173 @@
{
- "tags": [
- {
- "name": "text",
- "confidence": 0.9854570031166077
- },
- {
- "name": "design",
- "confidence": 0.9676092863082886
- },
- {
- "name": "screenshot",
- "confidence": 0.9044408798217773
- },
- {
- "name": "graphic",
- "confidence": 0.8791931867599487
- },
- {
- "name": "red",
- "confidence": 0.8448371887207031
- },
- {
- "name": "font",
- "confidence": 0.8189171552658081
- },
- {
- "name": "graphics",
- "confidence": 0.7044017314910889
- },
- {
- "name": "logo",
- "confidence": 0.6639798283576965
- },
- {
- "name": "typography",
- "confidence": 0.6407877802848816
- },
- {
- "name": "maroon",
- "confidence": 0.6387392282485962
- },
- {
- "name": "illustration",
- "confidence": 0.6350329518318176
- },
- {
- "name": "carmine",
- "confidence": 0.6345877647399902
- },
- {
- "name": "abstract",
- "confidence": 0.624541163444519
- },
- {
- "name": "vector graphics",
- "confidence": 0.21607014536857605
- },
- {
- "name": "clipart",
- "confidence": 0.20682862401008606
- }
- ],
- "description": {
- "tags": [
- "text"
- ],
- "captions": [
- {
- "text": "text",
- "confidence": 0.8448402285575867
+ "modelVersion": "2023-10-01",
+ "metadata": {
+ "height": 250,
+ "width": 772
+ },
+ "tagsResult": {
+ "values": [
+ {
+ "name": "text",
+ "confidence": 0.9854570031166077
+ },
+ {
+ "name": "design",
+ "confidence": 0.9676092863082886
+ },
+ {
+ "name": "screenshot",
+ "confidence": 0.9044408798217773
+ },
+ {
+ "name": "graphic",
+ "confidence": 0.8791931867599487
+ },
+ {
+ "name": "red",
+ "confidence": 0.8448371887207031
+ },
+ {
+ "name": "font",
+ "confidence": 0.8189171552658081
+ },
+ {
+ "name": "graphics",
+ "confidence": 0.7044017314910889
+ },
+ {
+ "name": "logo",
+ "confidence": 0.6639798283576965
+ },
+ {
+ "name": "typography",
+ "confidence": 0.6407877802848816
+ },
+ {
+ "name": "maroon",
+ "confidence": 0.6387392282485962
+ },
+ {
+ "name": "illustration",
+ "confidence": 0.6350329518318176
+ },
+ {
+ "name": "carmine",
+ "confidence": 0.6345877647399902
+ },
+ {
+ "name": "abstract",
+ "confidence": 0.624541163444519
+ },
+ {
+ "name": "vector graphics",
+ "confidence": 0.21607014536857605
+ },
+ {
+ "name": "clipart",
+ "confidence": 0.20682862401008606
}
]
},
- "requestId": "50fdeac0-9ef5-4e81-9e05-d392d15907ca",
- "metadata": {
- "height": 250,
- "width": 772,
- "format": "Png"
+ "captionResult": {
+ "text": "Text",
+ "confidence": 0.8448402285575867
+ },
+ "readResult": {
+ "blocks": [
+ {
+ "lines": [
+ {
+ "text": "CLASSIFAI_",
+ "boundingPolygon": [
+ {
+ "x": 193,
+ "y": 337
+ },
+ {
+ "x": 614,
+ "y": 348
+ },
+ {
+ "x": 617,
+ "y": 507
+ },
+ {
+ "x": 187,
+ "y": 510
+ }
+ ],
+ "words": [
+ {
+ "text": "CLASSIFAI_",
+ "boundingPolygon": [
+ {
+ "x": 188,
+ "y": 337
+ },
+ {
+ "x": 600,
+ "y": 341
+ },
+ {
+ "x": 599,
+ "y": 511
+ },
+ {
+ "x": 187,
+ "y": 510
+ }
+ ],
+ "confidence": 0.991
+ }
+ ]
+ },
+ {
+ "text": "Test",
+ "boundingPolygon": [
+ {
+ "x": 193,
+ "y": 337
+ },
+ {
+ "x": 614,
+ "y": 348
+ },
+ {
+ "x": 617,
+ "y": 507
+ },
+ {
+ "x": 187,
+ "y": 510
+ }
+ ],
+ "words": [
+ {
+ "text": "Test",
+ "boundingPolygon": [
+ {
+ "x": 188,
+ "y": 337
+ },
+ {
+ "x": 600,
+ "y": 341
+ },
+ {
+ "x": 599,
+ "y": 511
+ },
+ {
+ "x": 187,
+ "y": 510
+ }
+ ],
+ "confidence": 0.991
+ }
+ ]
+ }
+ ]
+ }
+ ]
}
}
diff --git a/tests/test-plugin/ocr.json b/tests/test-plugin/ocr.json
deleted file mode 100644
index 1b98a7e05..000000000
--- a/tests/test-plugin/ocr.json
+++ /dev/null
@@ -1,59 +0,0 @@
-{
- "language": "en",
- "textAngle": 0.0,
- "orientation": "Up",
- "regions": [
- {
- "boundingBox": "319,188,904,146",
- "lines": [
- {
- "boundingBox": "319,188,899,59",
- "words": [
- {
- "boundingBox": "319,188,250,48",
- "text": "ClassifAI"
- },
- {
- "boundingBox": "588,188,180,59",
- "text": "Brings"
- },
- {
- "boundingBox": "783,191,56,44",
- "text": "Al"
- },
- {
- "boundingBox": "856,190,104,46",
- "text": "and"
- },
- {
- "boundingBox": "979,188,239,48",
- "text": "Machine"
- }
- ]
- },
- {
- "boundingBox": "320,275,903,59",
- "words": [
- {
- "boundingBox": "320,275,245,59",
- "text": "Learning"
- },
- {
- "boundingBox": "582,275,245,48",
- "text": "Services"
- },
- {
- "boundingBox": "841,281,56,42",
- "text": "to"
- },
- {
- "boundingBox": "912,277,311,46",
- "text": "WordPress"
- }
- ]
- }
- ]
- }
- ],
- "modelVersion": "2021-04-01"
-}