6
6
7
7
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
8
8
9
- Note 1: the analyze overloads here should have been implemented in the `_patch.py` file in the `_operations` folder
10
- instead of here. That would have worked fine, except there is an issue with the generated Python
11
- ref-docs. The overloads do not show up. See this GitHub issue: https://github.com/Azure/autorest.python/issues/1315.
12
- To overcome this, the overloads are defined here. Consider moving them to the right place once the
13
- above issue is fixed.
14
-
15
- Note 2: Don't bother documenting the two overload methods below. The doc tool (sphinx) will not pick them up. Instead,
16
- document the 3rd method.
17
9
"""
18
- from typing import List , overload , Any , Optional , Union
10
+ from typing import List , Any , Optional , Union
19
11
from azure .core .tracing .decorator import distributed_trace
20
12
from . import models as _models
21
13
from ._operations ._operations import ImageAnalysisClientOperationsMixin
@@ -35,41 +27,73 @@ class ImageAnalysisClient(ImageAnalysisClientGenerated):
35
27
:paramtype api_version: str
36
28
"""
37
29
38
- @overload
39
- def analyze (
30
+ @distributed_trace
31
+ def analyze_from_url (
40
32
self ,
41
- * ,
42
33
image_url : str ,
43
34
visual_features : List [_models .VisualFeatures ],
44
- language : Optional [str ] = None ,
45
- gender_neutral_caption : Optional [bool ] = None ,
46
- smart_crops_aspect_ratios : Optional [List [float ]] = None ,
47
- model_version : Optional [str ] = None ,
48
- ** kwargs : Any
49
- ) -> _models .ImageAnalysisResult :
50
- ...
51
-
52
- @overload
53
- def analyze (
54
- self ,
55
35
* ,
56
- image_data : bytes ,
57
- visual_features : List [_models .VisualFeatures ],
58
36
language : Optional [str ] = None ,
59
37
gender_neutral_caption : Optional [bool ] = None ,
60
38
smart_crops_aspect_ratios : Optional [List [float ]] = None ,
61
39
model_version : Optional [str ] = None ,
62
40
** kwargs : Any
63
41
) -> _models .ImageAnalysisResult :
64
- ...
42
+ """Performs a single Image Analysis operation.
43
+
44
+ :param image_url: The publicly accessible URL of the image to analyze.
45
+ :type image_url: str
46
+ :param visual_features: A list of visual features to analyze. Required. Seven visual features
47
+ are supported: Caption, DenseCaptions, Read (OCR), Tags, Objects, SmartCrops, and People. At
48
+ least one visual feature must be specified.
49
+ :type visual_features: list[~azure.ai.vision.imageanalysis.models.VisualFeatures]
50
+ :keyword language: The desired language for result generation (a two-letter language code).
51
+ Defaults to 'en' (English). See https://aka.ms/cv-languages for a list of supported languages.
52
+ :paramtype language: str
53
+ :keyword gender_neutral_caption: Boolean flag for enabling gender-neutral captioning for
54
+ Caption and Dense Captions features. Defaults to 'false'.
55
+ Captions may contain gender terms (for example: 'man', 'woman', or 'boy', 'girl').
56
+ If you set this to 'true', those will be replaced with gender-neutral terms (for example:
57
+ 'person' or 'child').
58
+ :paramtype gender_neutral_caption: bool
59
+ :keyword smart_crops_aspect_ratios: A list of aspect ratios to use for smart cropping.
60
+ Defaults to one crop region with an aspect ratio the service sees fit between
61
+ 0.5 and 2.0 (inclusive). Aspect ratios are calculated by dividing the target crop
62
+ width in pixels by the height in pixels. When set, supported values are
63
+ between 0.75 and 1.8 (inclusive).
64
+ :paramtype smart_crops_aspect_ratios: list[float]
65
+ :keyword model_version: The version of cloud AI-model used for analysis. Defaults to 'latest',
66
+ for the latest AI model with recent improvements.
67
+ The format is the following: 'latest' or 'YYYY-MM-DD' or 'YYYY-MM-DD-preview',
68
+ where 'YYYY', 'MM', 'DD' are the year, month and day associated with the model.
69
+ If you would like to make sure analysis results do not change over time, set this
70
+ value to a specific model version.
71
+ :paramtype model_version: str
72
+ :return: ImageAnalysisResult. The ImageAnalysisResult is compatible with MutableMapping
73
+ :rtype: ~azure.ai.vision.imageanalysis.models.ImageAnalysisResult
74
+ :raises: ~azure.core.exceptions.HttpResponseError
75
+ """
76
+
77
+ visual_features_impl : List [Union [str , _models .VisualFeatures ]] = list (visual_features )
78
+
79
+ return ImageAnalysisClientOperationsMixin ._analyze_from_url ( # pylint: disable=protected-access
80
+ self ,
81
+ image_content = _models ._models .ImageUrl (url = image_url ), # pylint: disable=protected-access
82
+ visual_features = visual_features_impl ,
83
+ language = language ,
84
+ gender_neutral_caption = gender_neutral_caption ,
85
+ smart_crops_aspect_ratios = smart_crops_aspect_ratios ,
86
+ model_version = model_version ,
87
+ ** kwargs
88
+ )
89
+
65
90
66
91
@distributed_trace
67
92
def analyze (
68
93
self ,
69
- * ,
94
+ image_data : bytes ,
70
95
visual_features : List [_models .VisualFeatures ],
71
- image_data : Optional [bytes ] = None ,
72
- image_url : Optional [str ] = None ,
96
+ * ,
73
97
language : Optional [str ] = None ,
74
98
gender_neutral_caption : Optional [bool ] = None ,
75
99
smart_crops_aspect_ratios : Optional [List [float ]] = None ,
@@ -78,14 +102,12 @@ def analyze(
78
102
) -> _models .ImageAnalysisResult :
79
103
"""Performs a single Image Analysis operation.
80
104
81
- :keyword image_url: The publicly accessible URL of the image to analyze.
82
- :paramtype image_url: str
83
- :keyword image_data: A buffer containing the whole image to be analyzed.
84
- :paramtype image_data: bytes
85
- :keyword visual_features: A list of visual features to analyze. Required. Seven visual features
105
+ :param image_data: A buffer containing the whole image to be analyzed.
106
+ :type image_data: bytes
107
+ :param visual_features: A list of visual features to analyze. Required. Seven visual features
86
108
are supported: Caption, DenseCaptions, Read (OCR), Tags, Objects, SmartCrops, and People. At
87
109
least one visual feature must be specified.
88
- :paramtype visual_features: list[~azure.ai.vision.imageanalysis.models.VisualFeatures]
110
+ :type visual_features: list[~azure.ai.vision.imageanalysis.models.VisualFeatures]
89
111
:keyword language: The desired language for result generation (a two-letter language code).
90
112
Defaults to 'en' (English). See https://aka.ms/cv-languages for a list of supported languages.
91
113
:paramtype language: str
@@ -115,31 +137,16 @@ def analyze(
115
137
116
138
visual_features_impl : List [Union [str , _models .VisualFeatures ]] = list (visual_features )
117
139
118
- if image_url is not None :
119
- return ImageAnalysisClientOperationsMixin ._analyze_from_url ( # pylint: disable=protected-access
120
- self ,
121
- image_content = _models ._models .ImageUrl (url = image_url ), # pylint: disable=protected-access
122
- visual_features = visual_features_impl ,
123
- language = language ,
124
- gender_neutral_caption = gender_neutral_caption ,
125
- smart_crops_aspect_ratios = smart_crops_aspect_ratios ,
126
- model_version = model_version ,
127
- ** kwargs
128
- )
129
-
130
- if image_data is not None :
131
- return ImageAnalysisClientOperationsMixin ._analyze_from_image_data ( # pylint: disable=protected-access
132
- self ,
133
- image_content = image_data ,
134
- visual_features = visual_features_impl ,
135
- language = language ,
136
- gender_neutral_caption = gender_neutral_caption ,
137
- smart_crops_aspect_ratios = smart_crops_aspect_ratios ,
138
- model_version = model_version ,
139
- ** kwargs
140
- )
141
-
142
- raise ValueError ("Either image_data or image_url must be specified." )
140
+ return ImageAnalysisClientOperationsMixin ._analyze_from_image_data ( # pylint: disable=protected-access
141
+ self ,
142
+ image_content = image_data ,
143
+ visual_features = visual_features_impl ,
144
+ language = language ,
145
+ gender_neutral_caption = gender_neutral_caption ,
146
+ smart_crops_aspect_ratios = smart_crops_aspect_ratios ,
147
+ model_version = model_version ,
148
+ ** kwargs
149
+ )
143
150
144
151
145
152
__all__ : List [str ] = [
0 commit comments