'How to programatically get the Model id from google.cloud.automl with Python

Q: How can i programmatically get the model id when finished training the model?.

Goal: I will use that id to deploy the model without web interface.

Tried: At first, i thought it is in the response when training the model (operation.name). But the operation.name showed projects/${projectId}/locations/${location}/operations/${operationId}, which is not include model id. So i have no idea how to programmatically get the model id.

Sample code:

from google.cloud import automl_v1beta1 as automl
project_id ='***'
compute_region ='us-central1'
Dataset_name='***'
dataset_id='***'

def train_model():
           client = automl.AutoMlClient()            
           project_location = client.location_path(project_id, 
           compute_region)
           my_model = {"display_name": model_name,"dataset_id": dataset_id, "text_classification_model_metadata": {},}
           response = client.create_model(project_location, my_model)
           print("Training operation name: {}".format(response.operation.name))
           print("Training started...")                        
           model_id= response.split("/")[-1]                                        
           # Deploy model
           client1 = automl.AutoMlClient()
           model_full_id = client1.model_path(project_id, "us-central1", model_id)
           response1 = client1.deploy_model(name=model_full_id)              
           print("Model Deployment started...")
           # synchronous check of operation status.
           print("Model deployed. {}".format(response1.result()))

I was referring the below URL for my request but it is in node.js. Please help me with the Python code for the same.

How to programmatically get model id from google-cloud-automl with node.js client library

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source