GCP google visionについて
以下のリンクに記載の通り、コードを実行したところ、下記のエラーが発生しました。
どのように対処すれば良いのかわからず、困っております。
お手数ですが、対処方法についてご教示お願いいたします。
https://cloud.google.com/vision/docs/pdf#vision_text_detection_pdf_gcs-python
python
1def async_detect_document(gcs_source_uri, gcs_destination_uri): 2 """OCR with PDF/TIFF as source files on GCS""" 3 import json 4 import re 5 from google.cloud import vision 6 from google.cloud import storage 7 8 # Supported mime_types are: 'application/pdf' and 'image/tiff' 9 mime_type = 'application/pdf' 10 11 # How many pages should be grouped into each json output file. 12 batch_size = 2 13 14 client = vision.ImageAnnotatorClient() 15 16 feature = vision.Feature( 17 type_=vision.Feature.Type.DOCUMENT_TEXT_DETECTION) 18 19 gcs_source = vision.GcsSource(uri=gcs_source_uri) 20 input_config = vision.InputConfig( 21 gcs_source=gcs_source, mime_type=mime_type) 22 23 gcs_destination = vision.GcsDestination(uri=gcs_destination_uri) 24 output_config = vision.OutputConfig( 25 gcs_destination=gcs_destination, batch_size=batch_size) 26 27 async_request = vision.AsyncAnnotateFileRequest( 28 features=[feature], input_config=input_config, 29 output_config=output_config) 30 31 operation = client.async_batch_annotate_files( 32 requests=[async_request]) 33 34 print('Waiting for the operation to finish.') 35 operation.result(timeout=420) 36 37 # Once the request has completed and the output has been 38 # written to GCS, we can list all the output files. 39 storage_client = storage.Client() 40 41 match = re.match(r'gs://([^/]+)/(.+)', gcs_destination_uri) 42 bucket_name = match.group(1)←ここでエラーになります。 43 prefix = match.group(2) 44 45 bucket = storage_client.get_bucket(bucket_name) 46 47 # List objects with the given prefix. 48 blob_list = list(bucket.list_blobs(prefix=prefix)) 49 print('Output files:') 50 for blob in blob_list: 51 print(blob.name) 52 53 # Process the first output file from GCS. 54 # Since we specified batch_size=2, the first response contains 55 # the first two pages of the input file. 56 output = blob_list[0] 57 58 json_string = output.download_as_string() 59 response = json.loads(json_string) 60 61 # The actual response for the first page of the input file. 62 first_page_response = response['responses'][0] 63 annotation = first_page_response['fullTextAnnotation'] 64 65 # Here we print the full text from the first page. 66 # The response contains more information: 67 # annotation/pages/blocks/paragraphs/words/symbols 68 # including confidence scores and bounding boxes 69 print('Full text:\n') 70 print(annotation['text'])
(エラー画面)
AttributeError
1<ipython-input-144-ed7251c56f06> in <module> 2 40 3 41 match = re.match(r'gs://([^/]+)/(.+)', gcs_destination_uri) 4---> 42 bucket_name = match.group(1) 5 43 prefix = match.group(2) 6 44 7 8AttributeError: 'NoneType' object has no attribute 'group' 9 10 11 12
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/04/21 13:52