0

The following code gives the following Print Output:

-------Recognizing business card #1-------- Contact First Name: Chris has confidence: 1.0 Contact Last Name: Smith has confidence: 1.0

The code that provides the above output is:

bcUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/master/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/business_cards/business-card-english.jpg"

poller = form_recognizer_client.begin_recognize_business_cards_from_url(bcUrl)
business_cards = poller.result()

for idx, business_card in enumerate(business_cards):
    print("--------Recognizing business card #{}--------".format(idx+1))
    contact_names = business_card.fields.get("ContactNames")
    if contact_names:
        for contact_name in contact_names.value:
            print("Contact First Name: {} has confidence: {}".format(
                contact_name.value["FirstName"].value, contact_name.value["FirstName"].confidence
            ))
            print("Contact Last Name: {} has confidence: {}".format(
                contact_name.value["LastName"].value, contact_name.value["LastName"].confidence
            ))

I am trying refactor the code so as to output the results to a dataframe as follows:

import pandas as pd
    
field_list = ["FirstName", "LastName"]
df = pd.DataFrame(columns=field_list)
bcUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/master/sdk/formrecognizer/azure-ai formrecognizer/samples/sample_forms/business_cards/business-card-english.jpg"
    for blob in container.list_blobs():
      blob_url = container_url + "/" + blob.name
      poller = form_recognizer_client.begin_recognize_business_cards_from_url(bcUrl)
      business_cards = poller.result()
      print("Scanning " + blob.name + "...")
      
      for idx, business_card in enumerate(business_cards):
          single_df = pd.DataFrame(columns=field_list)
    
          for field in field_list:
            entry = business_card.fields.get(field)
            
            if entry:
              single_df[field] = [entry.value]
              
          single_df['FileName'] = blob.name
          df = df.append(single_df)
    
    df = df.reset_index(drop=True)
    df

However, my code does not provide any output:

Can someone take a look and let know why I'm not getting any output?

Patterson
  • 1,927
  • 1
  • 19
  • 56

1 Answers1

0

When I tried to connect blob storage, I got the same kind of error. I just followed the below syntax for connecting blob storage and also, I deleted .json and some other .fott files only I have the PDFs in the container. I run the same code without any problem it is working fine. Please follow below reference which has detailed information.

Install packages

Ref1

Connect to Azure Storage Container

Ref2

Enable Cognitive Services

Ref3

Send files to Cognitive Services

Ref4

Reference:

https://www.youtube.com/watch?v=hQ2NeO4c9iI&t=458s

Azure Databricks and Form Recognizer - Invalid Image or password protected - Stack Overflow

https://github.com/tomweinandy/form_recognizer_demo

B. B. Naga Sai Vamsi
  • 2,386
  • 2
  • 3
  • 11