-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from moe-mizrak/add-aws-request
feat: detectLabels functionality is added
- Loading branch information
Showing
31 changed files
with
1,615 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!-- | ||
- Fill in the form below correctly. This will help the Peck team to understand the PR and also work on it. | ||
--> | ||
|
||
### What: | ||
|
||
- [ ] Bug fix (non-breaking change which fixes an issue) | ||
- [ ] New feature (non-breaking change which adds functionality) | ||
- [ ] Update the README.md | ||
- [ ] Misc. change (internal, infrastructure, maintenance, etc.) | ||
|
||
### Description: | ||
|
||
<!-- describe what your PR is solving --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Main | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
os: [ ubuntu-latest ] | ||
php: [ 8.2, 8.3, 8.4 ] | ||
laravel: [ 10.*, 11.* ] | ||
dependency-version: [ prefer-lowest, prefer-stable ] | ||
|
||
name: Tests PHP${{ matrix.php }} - Laravel v${{ matrix.laravel }} | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP Environment | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: dom, mbstring, zip | ||
coverage: none | ||
|
||
- name: Cache Composer Dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.composer/cache/files | ||
key: dependencies-php-${{ matrix.php }}-L${{ matrix.laravel }}-${{ matrix.dependency-version }}-composer-${{ hashFiles('composer.json') }} | ||
|
||
- name: Install Composer Dependencies | ||
run: composer install --no-interaction --no-scripts --no-progress --prefer-dist | ||
|
||
- name: Run PHPUnit Tests | ||
run: vendor/bin/phpunit --log-junit phpunit-report.xml | ||
|
||
- name: Upload PHPUnit Report | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: PHPUnit Test Report | ||
path: phpunit-report.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,37 @@ | ||
<?php | ||
|
||
return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| AWS credentials | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may specify the credentials for AWS used to sign requests. | ||
| See https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.AwsClient.html#method___construct for more information. | ||
| | ||
*/ | ||
'credentials' => [ | ||
'key' => env('AWS_ACCESS_KEY_ID'), | ||
'secret' => env('AWS_SECRET_ACCESS_KEY'), | ||
], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| AWS region | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may specify the region to connect to. | ||
| See https://docs.aws.amazon.com/general/latest/gr/rande.html for a list of available regions. | ||
*/ | ||
'region' => env('AWS_REGION', 'us-east-1'), | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| AWS version of the webservice to utilize (e.g., 2006-03-01) | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may specify the version of the webservice. | ||
| See https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.AwsClient.html#method___construct for more information. | ||
*/ | ||
'version' => env('AWS_VERSION', 'latest'), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MoeMizrak\Rekognition\Data; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
/** | ||
* DetectLabelsData is for detectLabels method related context data such as image, features, maxLabels, minConfidence and settings. | ||
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#detectlabels | ||
* | ||
* @class DetectLabelsData | ||
*/ | ||
final class DetectLabelsData extends Data | ||
{ | ||
public function __construct( | ||
/* | ||
* The input image as base64-encoded bytes, image resource or an S3 object (Images stored in an S3 Bucket do not need to be base64-encoded). | ||
* | ||
* @param ImageData | ||
*/ | ||
public ImageData $image, | ||
|
||
/* | ||
* A list of the types of analysis to perform. | ||
* Specifying GENERAL_LABELS uses the label detection feature, while specifying IMAGE_PROPERTIES returns information regarding image color and quality. | ||
* default: GENERAL_LABELS | ||
* | ||
* @param array|null | ||
*/ | ||
public ?array $features = null, | ||
|
||
/* | ||
* Maximum number of labels you want the service to return in the response. The service returns the specified number of highest confidence labels. | ||
* Only valid when GENERAL_LABELS is specified as a feature type in the Feature input parameter. | ||
* | ||
* @param int|null | ||
*/ | ||
public ?int $maxLabels = null, | ||
|
||
/* | ||
* Specifies the minimum confidence level for the labels to return. | ||
* Amazon Rekognition doesn't return any labels with confidence lower than this specified value. | ||
* If MinConfidence is not specified, the operation returns labels with a confidence values greater than or equal to 55 percent. | ||
* Only valid when GENERAL_LABELS is specified as a feature type in the Feature input parameter. | ||
* | ||
* @param float|null | ||
*/ | ||
public ?float $minConfidence = null, | ||
|
||
/* | ||
* A list of the filters to be applied to returned detected labels and image properties. | ||
* | ||
* @param SettingsData|null | ||
*/ | ||
public ?SettingsData $settings = null | ||
) {} | ||
|
||
/** | ||
* Convert the data to an AWS Rekognition array format, excluding null values. | ||
* | ||
* @return array | ||
*/ | ||
public function toRekognitionDataFormat(): array | ||
{ | ||
return array_filter( | ||
[ | ||
'Image' => $this->image->toRekognitionDataFormat(), | ||
'Features' => $this->features, | ||
'MaxLabels' => $this->maxLabels, | ||
'MinConfidence' => $this->minConfidence, | ||
'Settings' => $this->settings?->toRekognitionDataFormat(), | ||
], | ||
fn ($value) => $value !== null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MoeMizrak\Rekognition\Data; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
/** | ||
* DetectLabelsImagePropertiesSettingsData is settings for the IMAGE_PROPERTIES feature type. | ||
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#shape-detectlabelsimagepropertiessettings | ||
* | ||
* @class DetectLabelsImagePropertiesSettingsData | ||
*/ | ||
final class DetectLabelsImagePropertiesSettingsData extends Data | ||
{ | ||
public function __construct( | ||
/* | ||
* The maximum number of dominant colors to return when detecting labels in an image. | ||
* The default value is 10. | ||
* | ||
* @param int|null | ||
*/ | ||
public ?int $maxDominantColors = null, | ||
) {} | ||
|
||
/** | ||
* Convert the data to an AWS Rekognition array format. | ||
* | ||
* @return array | ||
*/ | ||
public function toRekognitionDataFormat(): array | ||
{ | ||
return array_filter( | ||
[ | ||
'MaxDominantColors' => $this->maxDominantColors, | ||
], | ||
fn ($value) => $value !== null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MoeMizrak\Rekognition\Data; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
/** | ||
* Contains filters for the object labels returned by DetectLabels. Filters can be inclusive, exclusive, or a combination of both and can be applied to individual labels or entire label categories. | ||
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#shape-generallabelssettings | ||
* To see a list of label categories: https://docs.aws.amazon.com/rekognition/latest/dg/labels.html | ||
* | ||
* @class GeneralLabelsSettingsData | ||
*/ | ||
final class GeneralLabelsSettingsData extends Data | ||
{ | ||
public function __construct( | ||
/* | ||
* The label categories that should be excluded from the return from DetectLabels. | ||
* | ||
* @param array|null | ||
*/ | ||
public ?array $labelCategoryExclusionFilters = null, | ||
|
||
/* | ||
* The label categories that should be included in the return from DetectLabels. | ||
* | ||
* @param array|null | ||
*/ | ||
public ?array $labelCategoryInclusionFilters = null, | ||
|
||
/* | ||
* The labels that should be excluded from the return from DetectLabels. | ||
* | ||
* @param array|null | ||
*/ | ||
public ?array $labelExclusionFilters = null, | ||
|
||
/* | ||
* The labels that should be included in the return from DetectLabels. | ||
* | ||
* @param array|null | ||
*/ | ||
public ?array $labelInclusionFilters = null, | ||
) {} | ||
|
||
/** | ||
* Convert the data to an AWS Rekognition array format. | ||
* | ||
* @return array | ||
*/ | ||
public function toRekognitionDataFormat(): array | ||
{ | ||
return array_filter( | ||
[ | ||
'LabelCategoryExclusionFilters' => $this->labelCategoryExclusionFilters, | ||
'LabelCategoryInclusionFilters' => $this->labelCategoryInclusionFilters, | ||
'LabelExclusionFilters' => $this->labelExclusionFilters, | ||
'LabelInclusionFilters' => $this->labelInclusionFilters, | ||
], | ||
fn ($value) => $value !== null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MoeMizrak\Rekognition\Data; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
/** | ||
* Provides the input image either as bytes or an S3 object. | ||
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#shape-image | ||
* Also check: https://docs.aws.amazon.com/rekognition/latest/dg/images-information.html | ||
* | ||
* @class ImageData | ||
*/ | ||
final class ImageData extends Data | ||
{ | ||
public function __construct( | ||
/* | ||
* Blob of image bytes up to 5 MBs. | ||
* | ||
* @param string|resource|StreamInterface|null | ||
*/ | ||
public mixed $bytes = null, | ||
|
||
/* | ||
* Identifies an S3 object as the image source. | ||
* | ||
* @param S3ObjectData|null | ||
*/ | ||
public ?S3ObjectData $s3Object = null | ||
) {} | ||
|
||
/** | ||
* Convert the data to an AWS Rekognition array format. | ||
* | ||
* @return array | ||
*/ | ||
public function toRekognitionDataFormat(): array | ||
{ | ||
return array_filter( | ||
[ | ||
'Bytes' => $this->bytes, | ||
'S3Object' => $this->s3Object?->toRekognitionDataFormat(), | ||
], | ||
fn ($value) => $value !== null | ||
); | ||
} | ||
} |
Oops, something went wrong.