Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(


class FormRecognizerClient(SDKClient):
"""Extracts information from forms and images into structured data based on a model created by a set of representative training forms.
"""FormRecognizerClient

:ivar config: Configuration for client.
:vartype config: FormRecognizerClientConfiguration
Expand All @@ -73,7 +73,7 @@ def __init__(


def train_custom_model(
self, source, custom_headers=None, raw=False, **operation_config):
self, source, source_filter=None, custom_headers=None, raw=False, **operation_config):
"""Train Model.

Create and train a custom model. The train request must include a
Expand All @@ -92,6 +92,10 @@ def train_custom_model(

:param source: Get or set source path.
:type source: str
:param source_filter: Get or set filter to further search the
source path for content.
:type source_filter:
~azure.cognitiveservices.formrecognizer.models.TrainSourceFilter
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
Expand All @@ -103,7 +107,7 @@ def train_custom_model(
:raises:
:class:`ErrorResponseException<azure.cognitiveservices.formrecognizer.models.ErrorResponseException>`
"""
train_request = models.TrainRequest(source=source)
train_request = models.TrainRequest(source=source, source_filter=source_filter)

# Construct URL
url = self.train_custom_model.metadata['url']
Expand Down Expand Up @@ -421,3 +425,173 @@ def analyze_with_custom_model(

return deserialized
analyze_with_custom_model.metadata = {'url': '/custom/models/{id}/analyze'}

def batch_read_receipt(
self, url, custom_headers=None, raw=False, **operation_config):
"""Batch Read Receipt operation. The response contains a field called
'Operation-Location', which contains the URL that you must use for your
'Get Read Receipt Result' operation.

:param url: Publicly reachable URL of an image.
:type url: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: None or ClientRawResponse if raw=true
:rtype: None or ~msrest.pipeline.ClientRawResponse
:raises:
:class:`ComputerVisionErrorException<azure.cognitiveservices.formrecognizer.models.ComputerVisionErrorException>`
"""
image_url = models.ImageUrl(url=url)

# Construct URL
url = self.batch_read_receipt.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}

# Construct headers
header_parameters = {}
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if custom_headers:
header_parameters.update(custom_headers)

# Construct body
body_content = self._serialize.body(image_url, 'ImageUrl')

# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [202]:
raise models.ComputerVisionErrorException(self._deserialize, response)

if raw:
client_raw_response = ClientRawResponse(None, response)
client_raw_response.add_headers({
'Operation-Location': 'str',
})
return client_raw_response
batch_read_receipt.metadata = {'url': '/prebuilt/receipt/asyncBatchAnalyze'}

def get_read_receipt_result(
self, operation_id, custom_headers=None, raw=False, **operation_config):
"""This interface is used for getting the analysis results of a 'Batch
Read Receipt' operation. The URL to this interface should be retrieved
from the 'Operation-Location' field returned from the 'Batch Read
Receipt' operation.

:param operation_id: Id of read operation returned in the response of
a 'Batch Read Receipt' operation.
:type operation_id: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: ReadReceiptResult or ClientRawResponse if raw=true
:rtype:
~azure.cognitiveservices.formrecognizer.models.ReadReceiptResult or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`ComputerVisionErrorException<azure.cognitiveservices.formrecognizer.models.ComputerVisionErrorException>`
"""
# Construct URL
url = self.get_read_receipt_result.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True),
'operationId': self._serialize.url("operation_id", operation_id, 'str')
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}

# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
if custom_headers:
header_parameters.update(custom_headers)

# Construct and send request
request = self._client.get(url, query_parameters, header_parameters)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [200]:
raise models.ComputerVisionErrorException(self._deserialize, response)

deserialized = None

if response.status_code == 200:
deserialized = self._deserialize('ReadReceiptResult', response)

if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response

return deserialized
get_read_receipt_result.metadata = {'url': '/prebuilt/receipt/operations/{operationId}'}

def batch_read_receipt_in_stream(
self, image, custom_headers=None, raw=False, callback=None, **operation_config):
"""Read Receipt operation. When you use the 'Batch Read Receipt'
interface, the response contains a field called 'Operation-Location'.
The 'Operation-Location' field contains the URL that you must use for
your 'Get Read Receipt Result' operation.

:param image: An image stream.
:type image: Generator
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param callback: When specified, will be called with each chunk of
data that is streamed. The callback should take two arguments, the
bytes of the current chunk of data and the response object. If the
data is uploading, response will be None.
:type callback: Callable[Bytes, response=None]
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: None or ClientRawResponse if raw=true
:rtype: None or ~msrest.pipeline.ClientRawResponse
:raises:
:class:`ComputerVisionErrorException<azure.cognitiveservices.formrecognizer.models.ComputerVisionErrorException>`
"""
# Construct URL
url = self.batch_read_receipt_in_stream.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}

# Construct headers
header_parameters = {}
header_parameters['Content-Type'] = 'application/octet-stream'
if custom_headers:
header_parameters.update(custom_headers)

# Construct body
body_content = self._client.stream_upload(image, callback)

# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [202]:
raise models.ComputerVisionErrorException(self._deserialize, response)

if raw:
client_raw_response = ClientRawResponse(None, response)
client_raw_response.add_headers({
'Operation-Location': 'str',
})
return client_raw_response
batch_read_receipt_in_stream.metadata = {'url': '/prebuilt/receipt/asyncBatchAnalyze'}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# --------------------------------------------------------------------------

try:
from .train_source_filter_py3 import TrainSourceFilter
from .train_request_py3 import TrainRequest
from .form_document_report_py3 import FormDocumentReport
from .form_operation_error_py3 import FormOperationError
Expand All @@ -26,7 +27,19 @@
from .extracted_table_py3 import ExtractedTable
from .extracted_page_py3 import ExtractedPage
from .analyze_result_py3 import AnalyzeResult
from .word_py3 import Word
from .line_py3 import Line
from .text_recognition_result_py3 import TextRecognitionResult
from .element_reference_py3 import ElementReference
from .field_value_py3 import FieldValue
from .understanding_result_py3 import UnderstandingResult
from .read_receipt_result_py3 import ReadReceiptResult
from .string_value_py3 import StringValue
from .number_value_py3 import NumberValue
from .computer_vision_error_py3 import ComputerVisionError, ComputerVisionErrorException
from .image_url_py3 import ImageUrl
except (SyntaxError, ImportError):
from .train_source_filter import TrainSourceFilter
from .train_request import TrainRequest
from .form_document_report import FormDocumentReport
from .form_operation_error import FormOperationError
Expand All @@ -43,8 +56,25 @@
from .extracted_table import ExtractedTable
from .extracted_page import ExtractedPage
from .analyze_result import AnalyzeResult
from .word import Word
from .line import Line
from .text_recognition_result import TextRecognitionResult
from .element_reference import ElementReference
from .field_value import FieldValue
from .understanding_result import UnderstandingResult
from .read_receipt_result import ReadReceiptResult
from .string_value import StringValue
from .number_value import NumberValue
from .computer_vision_error import ComputerVisionError, ComputerVisionErrorException
from .image_url import ImageUrl
from .form_recognizer_client_enums import (
TextOperationStatusCodes,
TextRecognitionResultDimensionUnit,
TextRecognitionResultConfidenceClass,
)

__all__ = [
'TrainSourceFilter',
'TrainRequest',
'FormDocumentReport',
'FormOperationError',
Expand All @@ -61,4 +91,18 @@
'ExtractedTable',
'ExtractedPage',
'AnalyzeResult',
'Word',
'Line',
'TextRecognitionResult',
'ElementReference',
'FieldValue',
'UnderstandingResult',
'ReadReceiptResult',
'StringValue',
'NumberValue',
'ComputerVisionError', 'ComputerVisionErrorException',
'ImageUrl',
'TextOperationStatusCodes',
'TextRecognitionResultDimensionUnit',
'TextRecognitionResultConfidenceClass',
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from msrest.serialization import Model
from msrest.exceptions import HttpOperationError


class ComputerVisionError(Model):
"""Details about the API request error.

All required parameters must be populated in order to send to Azure.

:param code: Required. The error code.
:type code: object
:param message: Required. A message explaining the error reported by the
service.
:type message: str
:param request_id: A unique request identifier.
:type request_id: str
"""

_validation = {
'code': {'required': True},
'message': {'required': True},
}

_attribute_map = {
'code': {'key': 'code', 'type': 'object'},
'message': {'key': 'message', 'type': 'str'},
'request_id': {'key': 'requestId', 'type': 'str'},
}

def __init__(self, **kwargs):
super(ComputerVisionError, self).__init__(**kwargs)
self.code = kwargs.get('code', None)
self.message = kwargs.get('message', None)
self.request_id = kwargs.get('request_id', None)


class ComputerVisionErrorException(HttpOperationError):
"""Server responsed with exception of type: 'ComputerVisionError'.

:param deserialize: A deserializer
:param response: Server response to be deserialized.
"""

def __init__(self, deserialize, response, *args):

super(ComputerVisionErrorException, self).__init__(deserialize, response, 'ComputerVisionError', *args)
Loading