Skip to content

Commit 6aa69df

Browse files
busunkim96dandhlee
authored andcommitted
feat!: move to microgen (#61)
See UPGRADING.md
1 parent 0f97486 commit 6aa69df

File tree

87 files changed

+331
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+331
-336
lines changed

automl/beta/batch_predict.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,27 @@ def batch_predict(
2727
prediction_client = automl.PredictionServiceClient()
2828

2929
# Get the full path of the model.
30-
model_full_id = prediction_client.model_path(
30+
model_full_id = automl.AutoMlClient.model_path(
3131
project_id, "us-central1", model_id
3232
)
3333

34-
gcs_source = automl.types.GcsSource(input_uris=[input_uri])
34+
gcs_source = automl.GcsSource(input_uris=[input_uri])
3535

36-
input_config = automl.types.BatchPredictInputConfig(gcs_source=gcs_source)
37-
gcs_destination = automl.types.GcsDestination(output_uri_prefix=output_uri)
38-
output_config = automl.types.BatchPredictOutputConfig(
36+
input_config = automl.BatchPredictInputConfig(gcs_source=gcs_source)
37+
gcs_destination = automl.GcsDestination(output_uri_prefix=output_uri)
38+
output_config = automl.BatchPredictOutputConfig(
3939
gcs_destination=gcs_destination
4040
)
4141
params = {}
4242

43+
request = automl.BatchPredictRequest(
44+
name=model_full_id,
45+
input_config=input_config,
46+
output_config=output_config,
47+
params=params
48+
)
4349
response = prediction_client.batch_predict(
44-
model_full_id, input_config, output_config, params=params
50+
request=request
4551
)
4652

4753
print("Waiting for operation to complete...")

automl/beta/cancel_operation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def sample_cancel_operation(project, operation_id):
3131

3232
client = automl_v1beta1.AutoMlClient()
3333

34-
operations_client = client.transport._operations_client
34+
operations_client = client._transport.operations_client
3535

3636
# project = '[Google Cloud Project ID]'
3737
# operation_id = '[Operation ID]'

automl/beta/delete_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def delete_dataset(project_id="YOUR_PROJECT_ID", dataset_id="YOUR_DATASET_ID"):
2424
dataset_full_id = client.dataset_path(
2525
project_id, "us-central1", dataset_id
2626
)
27-
response = client.delete_dataset(dataset_full_id)
27+
response = client.delete_dataset(name=dataset_full_id)
2828

2929
print("Dataset deleted. {}".format(response.result()))
3030
# [END automl_delete_dataset_beta]

automl/beta/delete_dataset_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
@pytest.fixture(scope="function")
2828
def dataset_id():
2929
client = automl.AutoMlClient()
30-
project_location = client.location_path(PROJECT_ID, "us-central1")
30+
project_location = f"projects/{PROJECT_ID}/locations/us-central1"
3131
display_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32]
32-
metadata = automl.types.TextExtractionDatasetMetadata()
33-
dataset = automl.types.Dataset(
32+
metadata = automl.TextExtractionDatasetMetadata()
33+
dataset = automl.Dataset(
3434
display_name=display_name, text_extraction_dataset_metadata=metadata
3535
)
36-
response = client.create_dataset(project_location, dataset)
36+
response = client.create_dataset(parent=project_location, dataset=dataset)
3737
dataset_id = response.name.split("/")[-1]
3838

3939
yield dataset_id

automl/beta/delete_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def delete_model(project_id, model_id):
2525
client = automl.AutoMlClient()
2626
# Get the full path of the model.
2727
model_full_id = client.model_path(project_id, "us-central1", model_id)
28-
response = client.delete_model(model_full_id)
28+
response = client.delete_model(name=model_full_id)
2929

3030
print("Model deleted. {}".format(response.result()))
3131
# [END automl_delete_model_beta]

automl/beta/get_model.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def get_model(project_id, model_id):
2525
client = automl.AutoMlClient()
2626
# Get the full path of the model.
2727
model_full_id = client.model_path(project_id, "us-central1", model_id)
28-
model = client.get_model(model_full_id)
28+
model = client.get_model(name=model_full_id)
2929

3030
# Retrieve deployment state.
31-
if model.deployment_state == automl.enums.Model.DeploymentState.DEPLOYED:
31+
if model.deployment_state == automl.Model.DeploymentState.DEPLOYED:
3232
deployment_state = "deployed"
3333
else:
3434
deployment_state = "undeployed"
@@ -37,8 +37,6 @@ def get_model(project_id, model_id):
3737
print("Model name: {}".format(model.name))
3838
print("Model id: {}".format(model.name.split("/")[-1]))
3939
print("Model display name: {}".format(model.display_name))
40-
print("Model create time:")
41-
print("\tseconds: {}".format(model.create_time.seconds))
42-
print("\tnanos: {}".format(model.create_time.nanos))
40+
print("Model create time: {}".format(model.create_time))
4341
print("Model deployment state: {}".format(deployment_state))
4442
# [END automl_get_model_beta]

automl/beta/get_model_evaluation.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,15 @@ def get_model_evaluation(project_id, model_id, model_evaluation_id):
2626

2727
client = automl.AutoMlClient()
2828
# Get the full path of the model evaluation.
29-
model_evaluation_full_id = client.model_evaluation_path(
30-
project_id, "us-central1", model_id, model_evaluation_id
31-
)
29+
model_path = client.model_path(project_id, "us-central1", model_id)
30+
model_evaluation_full_id = f"{model_path}/modelEvaluations/{model_evaluation_id}"
3231

3332
# Get complete detail of the model evaluation.
34-
response = client.get_model_evaluation(model_evaluation_full_id)
33+
response = client.get_model_evaluation(name=model_evaluation_full_id)
3534

3635
print("Model evaluation name: {}".format(response.name))
3736
print("Model annotation spec id: {}".format(response.annotation_spec_id))
38-
print("Create Time:")
39-
print("\tseconds: {}".format(response.create_time.seconds))
40-
print("\tnanos: {}".format(response.create_time.nanos / 1e9))
37+
print("Create Time: {}".format(response.create_time))
4138
print(
4239
"Evaluation example count: {}".format(response.evaluated_example_count)
4340
)

automl/beta/get_model_evaluation_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
def model_evaluation_id():
2828
client = automl.AutoMlClient()
2929
model_full_id = client.model_path(PROJECT_ID, "us-central1", MODEL_ID)
30-
generator = client.list_model_evaluations(model_full_id, "").pages
31-
page = next(generator)
32-
evaluation = page.next()
30+
request = automl.ListModelEvaluationsRequest(
31+
parent=model_full_id,
32+
filter=""
33+
)
34+
evaluations = client.list_model_evaluations(request=request)
35+
evaluation = next(iter(evaluations))
3336
model_evaluation_id = evaluation.name.split(
3437
"{}/modelEvaluations/".format(MODEL_ID)
3538
)[1].split("\n")[0]

automl/beta/get_operation_status.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_operation_status(
2424
client = automl.AutoMlClient()
2525

2626
# Get the latest state of a long-running operation.
27-
response = client.transport._operations_client.get_operation(
27+
response = client._transport.operations_client.get_operation(
2828
operation_full_id
2929
)
3030

automl/beta/get_operation_status_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
@pytest.fixture(scope="function")
2626
def operation_id():
2727
client = automl.AutoMlClient()
28-
project_location = client.location_path(PROJECT_ID, "us-central1")
29-
generator = client.transport._operations_client.list_operations(
28+
project_location = f"projects/{PROJECT_ID}/locations/us-central1"
29+
generator = client._transport.operations_client.list_operations(
3030
project_location, filter_=""
3131
).pages
3232
page = next(generator)

automl/beta/import_dataset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def import_dataset(
3030
)
3131
# Get the multiple Google Cloud Storage URIs
3232
input_uris = path.split(",")
33-
gcs_source = automl.types.GcsSource(input_uris=input_uris)
34-
input_config = automl.types.InputConfig(gcs_source=gcs_source)
33+
gcs_source = automl.GcsSource(input_uris=input_uris)
34+
input_config = automl.InputConfig(gcs_source=gcs_source)
3535
# Import data from the input URI
36-
response = client.import_data(dataset_full_id, input_config)
36+
response = client.import_data(name=dataset_full_id, input_config=input_config)
3737

3838
print("Processing import...")
3939
print("Data imported. {}".format(response.result()))

automl/beta/list_datasets.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ def list_datasets(project_id="YOUR_PROJECT_ID"):
2222
"""List datasets."""
2323
client = automl.AutoMlClient()
2424
# A resource that represents Google Cloud Platform location.
25-
project_location = client.location_path(project_id, "us-central1")
25+
project_location = f"projects/{project_id}/locations/us-central1"
2626

2727
# List all the datasets available in the region.
28-
response = client.list_datasets(project_location, "")
28+
request = automl.ListDatasetsRequest(parent=project_location, filter="")
29+
response = client.list_datasets(request=request)
2930

3031
print("List of datasets:")
3132
for dataset in response:
3233
print("Dataset name: {}".format(dataset.name))
3334
print("Dataset id: {}".format(dataset.name.split("/")[-1]))
3435
print("Dataset display name: {}".format(dataset.display_name))
35-
print("Dataset create time:")
36-
print("\tseconds: {}".format(dataset.create_time.seconds))
37-
print("\tnanos: {}".format(dataset.create_time.nanos))
36+
print("Dataset create time: {}".format(dataset.create_time))
3837
# [END automl_video_object_tracking_list_datasets_beta]
3938

4039
print(

automl/beta/list_models.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ def list_models(project_id):
2323

2424
client = automl.AutoMlClient()
2525
# A resource that represents Google Cloud Platform location.
26-
project_location = client.location_path(project_id, "us-central1")
27-
response = client.list_models(project_location, "")
26+
project_location = f"projects/{project_id}/locations/us-central1"
27+
request = automl.ListModelsRequest(parent=project_location, filter="")
28+
response = client.list_models(request=request)
2829

2930
print("List of models:")
3031
for model in response:
3132
# Display the model information.
3233
if (
3334
model.deployment_state
34-
== automl.enums.Model.DeploymentState.DEPLOYED
35+
== automl.Model.DeploymentState.DEPLOYED
3536
):
3637
deployment_state = "deployed"
3738
else:
@@ -40,8 +41,6 @@ def list_models(project_id):
4041
print("Model name: {}".format(model.name))
4142
print("Model id: {}".format(model.name.split("/")[-1]))
4243
print("Model display name: {}".format(model.display_name))
43-
print("Model create time:")
44-
print("\tseconds: {}".format(model.create_time.seconds))
45-
print("\tnanos: {}".format(model.create_time.nanos))
44+
print("Model create time: {}".format(model.create_time))
4645
print("Model deployment state: {}".format(deployment_state))
4746
# [END automl_list_models_beta]

automl/beta/set_endpoint.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ def set_endpoint(project_id):
2727

2828
# A resource that represents Google Cloud Platform location.
2929
# project_id = 'YOUR_PROJECT_ID'
30-
project_location = client.location_path(project_id, 'eu')
30+
project_location = f"projects/{project_id}/locations/eu"
3131
# [END automl_set_endpoint]
3232

3333
# List all the datasets available
3434
# Note: Create a dataset in `eu`, before calling `list_datasets`.
35+
request = automl.ListDatasetsRequest(
36+
parent=project_location,
37+
filter=""
38+
)
3539
response = client.list_datasets(
36-
project_location, filter_='')
40+
request=request
41+
)
3742

3843
for dataset in response:
3944
print(dataset)

automl/beta/video_classification_create_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def create_dataset(
2525
client = automl.AutoMlClient()
2626

2727
# A resource that represents Google Cloud Platform location.
28-
project_location = client.location_path(project_id, "us-central1")
29-
metadata = automl.types.VideoClassificationDatasetMetadata()
30-
dataset = automl.types.Dataset(
28+
project_location = f"projects/{project_id}/locations/us-central1"
29+
metadata = automl.VideoClassificationDatasetMetadata()
30+
dataset = automl.Dataset(
3131
display_name=display_name,
3232
video_classification_dataset_metadata=metadata,
3333
)
3434

3535
# Create a dataset with the dataset metadata in the region.
36-
created_dataset = client.create_dataset(project_location, dataset)
36+
created_dataset = client.create_dataset(parent=project_location, dataset=dataset)
3737

3838
# Display the dataset information
3939
print("Dataset name: {}".format(created_dataset.name))

automl/beta/video_classification_create_dataset_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def teardown():
3434
dataset_full_id = client.dataset_path(
3535
PROJECT_ID, "us-central1", DATASET_ID
3636
)
37-
response = client.delete_dataset(dataset_full_id)
37+
response = client.delete_dataset(name=dataset_full_id)
3838
response.result()
3939

4040

automl/beta/video_classification_create_model.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ def create_model(
2525
client = automl.AutoMlClient()
2626

2727
# A resource that represents Google Cloud Platform location.
28-
project_location = client.location_path(project_id, "us-central1")
28+
project_location = f"projects/{project_id}/locations/us-central1"
2929
# Leave model unset to use the default base model provided by Google
30-
metadata = automl.types.VideoClassificationModelMetadata()
31-
model = automl.types.Model(
30+
metadata = automl.VideoClassificationModelMetadata()
31+
model = automl.Model(
3232
display_name=display_name,
3333
dataset_id=dataset_id,
3434
video_classification_model_metadata=metadata,
3535
)
3636

3737
# Create a model with the model metadata in the region.
38-
response = client.create_model(project_location, model)
38+
response = client.create_model(parent=project_location, model=model)
3939

4040
print("Training operation name: {}".format(response.operation.name))
4141
print("Training started...")
4242
# [END automl_video_classification_create_model_beta]
43+
return response

automl/beta/video_classification_create_model_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ def teardown():
3131

3232
# Cancel the training operation
3333
client = automl.AutoMlClient()
34-
client.transport._operations_client.cancel_operation(OPERATION_ID)
34+
client._transport.operations_client.cancel_operation(OPERATION_ID)
3535

3636

3737
def test_video_classification_create_model(capsys):
3838
model_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32]
3939
video_classification_create_model.create_model(
4040
PROJECT_ID, DATASET_ID, model_name
4141
)
42+
4243
out, _ = capsys.readouterr()
4344
assert "Training started" in out
4445

automl/beta/video_object_tracking_create_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ def create_dataset(
2323
client = automl.AutoMlClient()
2424

2525
# A resource that represents Google Cloud Platform location.
26-
project_location = client.location_path(project_id, "us-central1")
27-
metadata = automl.types.VideoObjectTrackingDatasetMetadata()
28-
dataset = automl.types.Dataset(
26+
project_location = f"projects/{project_id}/locations/us-central1"
27+
metadata = automl.VideoObjectTrackingDatasetMetadata()
28+
dataset = automl.Dataset(
2929
display_name=display_name,
3030
video_object_tracking_dataset_metadata=metadata,
3131
)
3232

3333
# Create a dataset with the dataset metadata in the region.
34-
created_dataset = client.create_dataset(project_location, dataset)
34+
created_dataset = client.create_dataset(parent=project_location, dataset=dataset)
3535
# Display the dataset information
3636
print("Dataset name: {}".format(created_dataset.name))
3737
print("Dataset id: {}".format(created_dataset.name.split("/")[-1]))

automl/beta/video_object_tracking_create_dataset_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def teardown():
3333
dataset_full_id = client.dataset_path(
3434
PROJECT_ID, "us-central1", DATASET_ID
3535
)
36-
response = client.delete_dataset(dataset_full_id)
36+
response = client.delete_dataset(name=dataset_full_id)
3737
response.result()
3838

3939

automl/beta/video_object_tracking_create_model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ def create_model(
2525
client = automl.AutoMlClient()
2626

2727
# A resource that represents Google Cloud Platform loacation.
28-
project_location = client.location_path(project_id, "us-central1")
28+
project_location = f"projects/{project_id}/locations/us-central1"
2929
# Leave model unset to use the default base model provided by Google
30-
metadata = automl.types.VideoObjectTrackingModelMetadata()
31-
model = automl.types.Model(
30+
metadata = automl.VideoObjectTrackingModelMetadata()
31+
model = automl.Model(
3232
display_name=display_name,
3333
dataset_id=dataset_id,
3434
video_object_tracking_model_metadata=metadata,
3535
)
3636

3737
# Create a model with the model metadata in the region.
38-
response = client.create_model(project_location, model)
38+
response = client.create_model(parent=project_location, model=model)
3939

4040
print("Training operation name: {}".format(response.operation.name))
4141
print("Training started...")

automl/beta/video_object_tracking_create_model_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def teardown():
3131

3232
# Cancel the training operation
3333
client = automl.AutoMlClient()
34-
client.transport._operations_client.cancel_operation(OPERATION_ID)
34+
client._transport.operations_client.cancel_operation(OPERATION_ID)
3535

3636

3737
def test_video_classification_create_model(capsys):

0 commit comments

Comments
 (0)