Google AutoML Translate - can't access models

58 Views Asked by At

I trained models with Google AUtoML Translate. Under Google Cloud Console -> Predict (/predict) I can use the models to translate text but when I try to access them with API I run into errors. I created a service user and got the json authentication file.

When I run this python code:

import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="./xxxxxx.json"

from google.cloud import automl

# The below y's and z's are replaced with my project id and the model id
project_id = "yyyyyyy"
model_id = "zzzzzz"
file_path = "new1.txt"

prediction_client = automl.PredictionServiceClient()

model_full_id = automl.AutoMlClient.model_path(project_id, "us-central1", model_id)

with open(file_path, "rb") as content_file:
    content = content_file.read()
content.decode("utf-8")

text_snippet = automl.TextSnippet(content=content)
payload = automl.ExamplePayload(text_snippet=text_snippet)

response = prediction_client.predict(name=model_full_id, payload=payload)
translated_content = response.payload[0].translation.translated_content

print(f"Translated content: {translated_content.content}")

it gives me back this:

Traceback (most recent call last):
  File "C:\Python\Lib\site-packages\google\api_core\grpc_helpers.py", line 72, in error_remapped_callable
    return callable_(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\grpc\_channel.py", line 1030, in __call__
    return _end_unary_response_blocking(state, call, False, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\grpc\_channel.py", line 910, in _end_unary_response_blocking
    raise _InactiveRpcError(state)  # pytype: disable=not-instantiable
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.NOT_FOUND
        details = "Invalid resource ID"
        debug_error_string = "UNKNOWN:Error received from peer ipv4:142.251.163.95:443 {grpc_message:"Invalid resource ID", grpc_status:5, created_time:"2023-06-28T08:39:31.4117525+00:00"}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\temp\new\test.py", line 27, in <module>
    response = prediction_client.predict(name=model_full_id, payload=payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\google\cloud\automl_v1\services\prediction_service\client.py", line 635, in predict
    response = rpc(
               ^^^^
  File "C:\Python\Lib\site-packages\google\api_core\gapic_v1\method.py", line 113, in __call__
    return wrapped_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\google\api_core\timeout.py", line 120, in func_with_timeout
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\google\api_core\grpc_helpers.py", line 74, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.NotFound: 404 Invalid resource ID

I'm not sure how to debug this.

0

There are 0 best solutions below