Python API

Installation

NGC currently hosts the Riva API Python wheel. You will need to provide an NGC API key to retrieve it. The key can be provided either through the variable NGC_API_KEY or as a configuration file (which is automatically generated by running ngc config set).

  1. Retrieve the Riva resources from NGC and enter the directory.

    ngc registry resource download-version "nvidia/riva/riva_quickstart:1.9.0-beta"
    cd riva_quickstart_v1.9.0-beta
    
  2. Install the riva-speech Python wheel locally.

    pip install riva_api-1.9.0-beta-py3-none-any.whl
    

Python Example

The following steps show how you can integrate Riva AI Services into your own application using Python as an example. Full API documentation for all services and message types can be found in gRPC & Protocol Buffers.

  1. With the Python bindings successfully installed, integrate the Riva services in your application. For example, to classify the intent of a query, add:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    # required imports
    import grpc
    import riva_api.riva_nlp_pb2 as rnlp
    
    # establish connection to Riva server and initialize client
    channel = grpc.insecure_channel('localhost:50051')
    server = rnlp.RivaLanguageUnderstandingStub(channel)
    
    # make request
    req = rnlp.AnalyzeIntentRequest(query="How is the weather today in New England")
    resp = server.AnalyzeIntent(req)
    
    print(resp.intent.class_name)