Skip to content

Commit 0dbd577

Browse files
authored
[form recognizer] actionable issues for arch board (#11334)
* updated docstring for stream parameter to be 'bytes or IO[bytes' * directly pass stream to sync samples * got rid of unnecessary imports * looping through words and their confidences
1 parent 7cedad5 commit 0dbd577

File tree

7 files changed

+14
-12
lines changed

7 files changed

+14
-12
lines changed

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def begin_recognize_receipts(self, stream, **kwargs):
7878
7979
:param stream: .pdf, .jpg, .png or .tiff type file stream.
8080
Currently only supports US sales receipts.
81-
:type stream: stream
81+
:type stream: bytes or IO[bytes]
8282
:keyword bool include_text_content:
8383
Whether or not to include text elements such as lines and words in addition to form fields.
8484
:keyword str content_type: Media type of the body sent to the API. Content-type is
@@ -172,7 +172,7 @@ def begin_recognize_content(self, stream, **kwargs):
172172
'image/jpeg', 'image/png' or 'image/tiff'.
173173
174174
:param stream: .pdf, .jpg, .png or .tiff type file stream.
175-
:type stream: stream
175+
:type stream: bytes or IO[bytes]
176176
:keyword str content_type: Media type of the body sent to the API. Content-type is
177177
auto-detected, but can be overridden by passing this keyword argument. For options,
178178
see :class:`~azure.ai.formrecognizer.FormContentType`.
@@ -246,7 +246,7 @@ def begin_recognize_custom_forms(self, model_id, stream, **kwargs):
246246
247247
:param str model_id: Custom model identifier.
248248
:param stream: .pdf, .jpg, .png or .tiff type file stream.
249-
:type stream: stream
249+
:type stream: bytes or IO[bytes]
250250
:keyword bool include_text_content:
251251
Whether or not to include text elements such as lines and words in addition to form fields.
252252
:keyword str content_type: Media type of the body sent to the API. Content-type is

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async def recognize_receipts(
9090
9191
:param stream: .pdf, .jpg, .png or .tiff type file stream.
9292
Currently only supports US sales receipts.
93-
:type stream: stream
93+
:type stream: bytes or IO[bytes]
9494
:keyword bool include_text_content:
9595
Whether or not to include text elements such as lines and words in addition to form fields.
9696
:keyword str content_type: Media type of the body sent to the API. Content-type is
@@ -184,7 +184,7 @@ async def recognize_content(self, stream: Union[bytes, IO[bytes]], **kwargs: Any
184184
'image/jpeg', 'image/png' or 'image/tiff'.
185185
186186
:param stream: .pdf, .jpg, .png or .tiff type file stream.
187-
:type stream: stream
187+
:type stream: bytes or IO[bytes]
188188
:keyword str content_type: Media type of the body sent to the API. Content-type is
189189
auto-detected, but can be overridden by passing this keyword argument. For options,
190190
see :class:`~azure.ai.formrecognizer.FormContentType`.
@@ -258,7 +258,7 @@ async def recognize_custom_forms(
258258
259259
:param str model_id: Custom model identifier.
260260
:param stream: .pdf, .jpg, .png or .tiff type file stream.
261-
:type stream: stream
261+
:type stream: bytes or IO[bytes]
262262
:keyword bool include_text_content:
263263
Whether or not to include text elements such as lines and words in addition to form fields.
264264
:keyword str content_type: Media type of the body sent to the API. Content-type is

sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_content_async.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class RecognizeContentSampleAsync(object):
3939
async def recognize_content(self):
4040
# the sample forms are located in this file's parent's parent's files.
4141
path_to_sample_forms = Path(__file__).parent.parent.absolute() / Path("sample_forms/forms/Invoice_1.pdf")
42-
from azure.ai.formrecognizer import FormWord, FormLine
4342
# [START recognize_content_async]
4443
from azure.core.credentials import AzureKeyCredential
4544
from azure.ai.formrecognizer.aio import FormRecognizerClient
@@ -74,6 +73,8 @@ async def recognize_content(self):
7473
line.text,
7574
format_bounding_box(line.bounding_box)
7675
))
76+
for word in line.words:
77+
print("...Word '{}' has a confidence of {}".format(word.text, word.confidence))
7778
print("----------------------------------------")
7879

7980

sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_get_bounding_boxes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get_bounding_boxes(self):
4848
# Make sure your form's type is included in the list of form types the custom model can recognize
4949
with open("sample_forms/forms/Form_1.jpg", "rb") as f:
5050
poller = form_recognizer_client.begin_recognize_custom_forms(
51-
model_id=self.model_id, stream=f.read(), include_text_content=True
51+
model_id=self.model_id, stream=f, include_text_content=True
5252
)
5353
forms = poller.result()
5454

sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_content.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ class RecognizeContentSample(object):
3333
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]
3434

3535
def recognize_content(self):
36-
from azure.ai.formrecognizer import FormWord, FormLine
3736
# [START recognize_content]
3837
from azure.core.credentials import AzureKeyCredential
3938
from azure.ai.formrecognizer import FormRecognizerClient
4039
form_recognizer_client = FormRecognizerClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
4140
with open("sample_forms/forms/Invoice_1.pdf", "rb") as f:
42-
poller = form_recognizer_client.begin_recognize_content(stream=f.read())
41+
poller = form_recognizer_client.begin_recognize_content(stream=f)
4342
contents = poller.result()
4443

4544
for idx, content in enumerate(contents):
@@ -66,6 +65,8 @@ def recognize_content(self):
6665
line.text,
6766
format_bounding_box(line.bounding_box)
6867
))
68+
for word in line.words:
69+
print("...Word '{}' has a confidence of {}".format(word.text, word.confidence))
6970
print("----------------------------------------")
7071

7172

sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_custom_forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def recognize_custom_forms(self):
4343
# Make sure your form's type is included in the list of form types the custom model can recognize
4444
with open("sample_forms/forms/Form_1.jpg", "rb") as f:
4545
poller = form_recognizer_client.begin_recognize_custom_forms(
46-
model_id=self.model_id, stream=f.read()
46+
model_id=self.model_id, stream=f
4747
)
4848
forms = poller.result()
4949

sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_receipts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def recognize_receipts(self):
3636
endpoint=self.endpoint, credential=AzureKeyCredential(self.key)
3737
)
3838
with open("sample_forms/receipt/contoso-allinone.jpg", "rb") as f:
39-
poller = form_recognizer_client.begin_recognize_receipts(stream=f.read())
39+
poller = form_recognizer_client.begin_recognize_receipts(stream=f)
4040
receipts = poller.result()
4141

4242
for idx, receipt in enumerate(receipts):

0 commit comments

Comments
 (0)