Skip to content

Commit

Permalink
'web entities and pages'
Browse files Browse the repository at this point in the history
  • Loading branch information
faithoflifedev committed Jun 19, 2023
1 parent d15f408 commit 603f796
Show file tree
Hide file tree
Showing 20 changed files with 356 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.0.8

* web entities and pages
* dependency bump

## 1.0.7+7

* https://github.com/faithoflifedev/google_vision/issues/8
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ To use this package, add the dependency to your `pubspec.yaml` file:
```yaml
dependencies:
...
google_vision: ^1.0.7+7
google_vision: ^1.0.8
```
### Obtaining Authorization Credentials
Expand Down
23 changes: 23 additions & 0 deletions example/web_detection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:google_vision/google_vision.dart';

void main() async {
final googleVision =
await GoogleVision.withJwt('example/skc-live-decbd0969cbb.json');

final painter = Painter.fromFilePath('example/structures.png');

final requests = AnnotationRequests(requests: [
AnnotationRequest(
image: Image(painter: painter),
features: [Feature(maxResults: 10, type: 'WEB_DETECTION')])
]);

print('checking...');

AnnotatedResponses annotatedResponses =
await googleVision.annotate(requests: requests);

print(annotatedResponses);

print('done.\n');
}
2 changes: 1 addition & 1 deletion lib/meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
import 'dart:convert' show json;

final pubSpec = json.decode(
'{"name":"google_vision","version":"1.0.7+7","homepage":"https://github.com/faithoflifedev/google_vision","environment":{"sdk":">=2.17.0 <4.0.0"},"description":"Allows you to add Google Visions image labeling, face, logo, and landmark detection, OCR, and detection of explicit content, into applications.","dependencies":{"args":"^2.4.0","color":"^3.0.0","crypto_keys":"^0.3.0+1","dio":"^5.1.1","http":"^0.13.5","image":"^4.0.16","jose":"^0.3.3","json_annotation":"^4.8.0","retrofit":"^4.0.1","universal_io":"^2.0.4"},"dev_dependencies":{"build_runner":"^2.3.3","grinder":"^0.9.3","json_serializable":"^6.6.1","lints":"^2.0.1","publish_tools":"^0.1.0+9","retrofit_generator":"^6.0.0+3","test":"^1.23.1"},"executables":{"vision":""},"repository":"https://github.com/faithoflifedev/google_vision"}');
'{"name":"google_vision","version":"1.0.8","homepage":"https://github.com/faithoflifedev/google_vision","environment":{"sdk":">=2.17.0 <4.0.0"},"description":"Allows you to add Google Visions image labeling, face, logo, and landmark detection, OCR, and detection of explicit content, into applications.","dependencies":{"args":"^2.4.2","color":"^3.0.0","crypto_keys":"^0.3.0+1","dio":"^5.2.1+1","http":"^0.13.6","image":"^4.0.17","jose":"^0.3.3","json_annotation":"^4.8.1","retrofit":"^4.0.1","universal_io":"^2.2.2"},"dev_dependencies":{"build_runner":"^2.4.5","grinder":"^0.9.4","json_serializable":"^6.7.0","lints":"^2.1.1","publish_tools":"^0.1.0+10","retrofit_generator":"^7.0.1","test":"^1.24.3"},"executables":{"vision":""},"repository":"https://github.com/faithoflifedev/google_vision"}');
2 changes: 1 addition & 1 deletion lib/src/cmd/vision_helper_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:dio/dio.dart';
import 'package:google_vision/google_vision.dart';

/// Helper method to that retrieves error message string.
extension UsageExtension on DioError {
extension UsageExtension on DioException {
String get usage {
return response?.data['error']['errors'] == null
? message!
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cmd/vision_highlight_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class VisionHighlightCommand extends VisionHelper {
}
}
await image.writeAsJpeg(argResults!['output-file']);
} on DioError catch (err) {
} on DioException catch (err) {
throw UsageException('API usage error:', err.usage);
}
}
Expand Down
8 changes: 6 additions & 2 deletions lib/src/model/annotate_image_response.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:convert' show json;

import 'package:google_vision/src/model/safe_search_annotation.dart';
import 'package:json_annotation/json_annotation.dart';

import 'crop_hints_annotation.dart';
Expand All @@ -9,8 +8,10 @@ import 'image_annotation_context.dart';
import 'image_properties_annotation.dart';
import 'entity_annotation.dart';
import 'localized_object_annotation.dart';
import 'safe_search_annotation.dart';
import 'status.dart';
import 'full_text_annotation.dart';
import 'web_detection.dart';

part 'annotate_image_response.g.dart';

Expand Down Expand Up @@ -60,7 +61,9 @@ class AnnotateImageResponse {
@JsonKey(name: 'cropHintsAnnotation')
final CropHintsAnnotation? cropHintsAnnotation;

// TODO: webDetection
/// Relevant information for the image from the Internet.
@JsonKey(name: 'webDetection')
final WebDetection? webDetection;

// TODO: productSearchResults

Expand Down Expand Up @@ -110,6 +113,7 @@ class AnnotateImageResponse {
this.safeSearchAnnotation,
this.imagePropertiesAnnotation,
this.cropHintsAnnotation,
this.webDetection,
this.error,
this.context,
});
Expand Down
4 changes: 4 additions & 0 deletions lib/src/model/annotate_image_response.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions lib/src/model/web_detection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'dart:convert';

import 'package:json_annotation/json_annotation.dart';

import 'web_entity.dart';
import 'web_image.dart';
import 'web_label.dart';
import 'web_page.dart';

part 'web_detection.g.dart';

/// Relevant information for the image from the Internet.
@JsonSerializable()
class WebDetection {
/// Entity deduced from similar images on the Internet.
final List<WebEntity>? webEntities;

/// Fully matching images from the Internet.
final List<WebImage>? fullMatchingImages;

/// Partial matching images from the Internet.
final List<WebImage>? partialMatchingImages;

final List<WebPage>? pagesWithMatchingImages;

final List<WebImage>? visuallySimilarImages;

final List<WebLabel>? bestGuessLabels;

WebDetection({
this.webEntities,
this.fullMatchingImages,
this.partialMatchingImages,
this.pagesWithMatchingImages,
this.visuallySimilarImages,
this.bestGuessLabels,
});

factory WebDetection.fromJson(Map<String, dynamic> json) =>
_$WebDetectionFromJson(json);

Map<String, dynamic> toJson() => _$WebDetectionToJson(this);

@override
String toString() => jsonEncode(toJson());
}
39 changes: 39 additions & 0 deletions lib/src/model/web_detection.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions lib/src/model/web_entity.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'dart:convert';

import 'package:json_annotation/json_annotation.dart';

part 'web_entity.g.dart';

/// Entity deduced from similar images on the Internet.
@JsonSerializable()
class WebEntity {
/// Opaque entity ID.
final String entityId;

/// Overall relevancy score for the entity. Not normalized and not comparable
/// across different image queries.
final num score;

/// Canonical description of the entity, in English.
final String description;

WebEntity({
required this.entityId,
required this.score,
required this.description,
});

factory WebEntity.fromJson(Map<String, dynamic> json) =>
_$WebEntityFromJson(json);

Map<String, dynamic> toJson() => _$WebEntityToJson(this);

@override
String toString() => jsonEncode(toJson());
}
19 changes: 19 additions & 0 deletions lib/src/model/web_entity.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions lib/src/model/web_image.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'dart:convert';

import 'package:json_annotation/json_annotation.dart';

part 'web_image.g.dart';

/// Metadata for online images.
@JsonSerializable()
class WebImage {
/// The result image URL.
final String url;

/// (Deprecated) Overall relevancy score for the image.
final num? score;

WebImage({
required this.url,
required this.score,
});

factory WebImage.fromJson(Map<String, dynamic> json) =>
_$WebImageFromJson(json);

Map<String, dynamic> toJson() => _$WebImageToJson(this);

@override
String toString() => json.encode(toJson());
}
17 changes: 17 additions & 0 deletions lib/src/model/web_image.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions lib/src/model/web_label.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'dart:convert';

import 'package:json_annotation/json_annotation.dart';

part 'web_label.g.dart';

/// Label to provide extra metadata for the web detection.
@JsonSerializable()
class WebLabel {
/// Label for extra metadata.
final String label;

/// The BCP-47 language code for label, such as "en-US" or "sr-Latn". For more
/// information, see http://www.unicode.org/reports/tr35/#Unicode_locale_identifier.
final String? languageCode;

WebLabel({
required this.label,
this.languageCode,
});

factory WebLabel.fromJson(Map<String, dynamic> json) =>
_$WebLabelFromJson(json);

Map<String, dynamic> toJson() => _$WebLabelToJson(this);

@override
String toString() => json.encode(toJson());
}
17 changes: 17 additions & 0 deletions lib/src/model/web_label.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 603f796

Please sign in to comment.