Install Vertex AI client libraries

Google Distributed Cloud (GDC) air-gapped offers various Vertex AI services, including Optical Character Recognition (OCR), Translation, and Speech-to-Text. Each of these services provides its own pre-trained API, which you can install using client libraries.

Client libraries simplify accessing Vertex AI pre-trained APIs from supported languages on Distributed Cloud. Although you can use Vertex AI pre-trained APIs directly by making raw server requests, client libraries provide simplifications that reduce the required code.

Client libraries are the recommended option for accessing Vertex AI APIs programmatically, for example, on a JupyterLab notebook.

Install a Vertex AI client library in one of the following ways:

  • Extract the library file directly from the tar file.
  • Use a JupyterLab notebook to import the library.

This page describes the various types of client libraries that Distributed Cloud offers for Vertex AI pre-trained APIs and explains how to install them from the tar file. To import a client library from a notebook, see Create a notebook.

Vertex AI client libraries

Distributed Cloud offers different versions of OCR, Translation, and Speech-to-Text client libraries for CentOS and Ubuntu operating systems.

The naming conventions of Vertex AI client libraries in the tar file are based on the operating system, the service name, and the version. The filenames adhere to the following format:

OS-google-cloud-SERVICE-VERSION.tar.gz

Replace the following:

  • OS: the name of the operating system where you want to install the client library. Allowed values are centos and ubuntu.
  • SERVICE: the name of the Vertex AI service from which you want to download the client library. The following are the allowed values:

    • speech: the Speech-to-Text client library.
    • translate: the Translation client library.
    • vision: the OCR client library.
  • VERSION: the version number of the client library, for example, 3.8.0.

The following table contains the Vertex AI client libraries that Distributed Cloud supports:

Vertex AI service Operating system Filename
Speech-to-Text Centos centos-google-cloud-speech-2.15.0.tar.gz
Ubuntu ubuntu-google-cloud-speech-2.15.0.tar.gz
Translation Centos centos-google-cloud-translate-3.8.0.tar.gz
Ubuntu ubuntu-google-cloud-translate-3.8.0.tar.gz
OCR Centos centos-google-cloud-vision-3.0.0.tar.gz
Ubuntu ubuntu-google-cloud-vision-3.0.0.tar.gz

Before you begin

Before downloading the tar file and extracting client libraries, follow these steps:

  1. Set up a project for Vertex AI.

  2. Authenticate with gdcloud CLI:

    gdcloud auth login
    

    For more information about how to authenticate with your configured identity provider, see the gdcloud CLI authentication.

  3. Assign the Cloud AI Viewer (cloud-ai-viewer) role to a service account. The service account requires this role to access the Vertex AI services.

  4. Verify that you have installed Python version 3.7.

Install a client library

After completing the prerequisites, follow these steps to download the tar file, and use the tar file to install a client library:

  1. Download the client library you want to install:

    wget https://GDC_URL/.well-known/static/client-libraries/CLIENT_LIBRARY
    

    Replace the following:

    • GDC_URL: the URL of your organization in GDC.
    • CLIENT_LIBRARY: the filename of the client library you want to download.
  2. Extract the library file:

    tar -zxf CLIENT_LIBRARY
    
  3. Install the client library in Distributed Cloud:

    pip install -r FOLDER_NAME/requirements.txt --no-index --find-links FOLDER_NAME
    

    Replace FOLDER_NAME with the path to the local directory where you downloaded the library file.

  4. Import the client library using a Python script. The following sample shows a code snippet of a Python script that imports the Translation client library to illustrate what importing libraries looks like:

    from google.cloud import translate
    translate_client = translate.Client(
     client_options={"API_ENDPOINT": "https://foo-translation.googleapis.com"})
    result
    = translate_client.translate(text, target_language="ru")
    
    [...]
    

    This code sample is not complete. To make a Translation request, see Translate a language into another language or try a tutorial.

  5. Save the Python script with a name, for example, translation-service.py.

  6. Run the Python script:

    python SCRIPT_NAME
    

    Replace SCRIPT_NAME with the name you gave to your Python script, for example, translation-service.py.