150 lines
5.0 KiB
YAML
150 lines
5.0 KiB
YAML
description: |
|
|
automl_create_dataset_for_tables creates an empty Dataset for AutoML tables
|
|
implementation:
|
|
container:
|
|
args:
|
|
- --gcp-project-id
|
|
- inputValue: gcp_project_id
|
|
- --gcp-region
|
|
- inputValue: gcp_region
|
|
- --display-name
|
|
- inputValue: display_name
|
|
- if:
|
|
cond:
|
|
isPresent: description
|
|
then:
|
|
- --description
|
|
- inputValue: description
|
|
- if:
|
|
cond:
|
|
isPresent: tables_dataset_metadata
|
|
then:
|
|
- --tables-dataset-metadata
|
|
- inputValue: tables_dataset_metadata
|
|
- if:
|
|
cond:
|
|
isPresent: retry
|
|
then:
|
|
- --retry
|
|
- inputValue: retry
|
|
- if:
|
|
cond:
|
|
isPresent: timeout
|
|
then:
|
|
- --timeout
|
|
- inputValue: timeout
|
|
- if:
|
|
cond:
|
|
isPresent: metadata
|
|
then:
|
|
- --metadata
|
|
- inputValue: metadata
|
|
- '----output-paths'
|
|
- outputPath: dataset_path
|
|
- outputPath: create_time
|
|
- outputPath: dataset_id
|
|
command:
|
|
- python3
|
|
- -u
|
|
- -c
|
|
- |
|
|
from typing import NamedTuple
|
|
|
|
def automl_create_dataset_for_tables(
|
|
gcp_project_id: str,
|
|
gcp_region: str,
|
|
display_name: str,
|
|
description: str = None,
|
|
tables_dataset_metadata: dict = {},
|
|
retry=None, #=google.api_core.gapic_v1.method.DEFAULT,
|
|
timeout: float = None, #=google.api_core.gapic_v1.method.DEFAULT,
|
|
metadata: dict = None,
|
|
) -> NamedTuple('Outputs', [('dataset_path', str), ('create_time', str), ('dataset_id', str)]):
|
|
'''automl_create_dataset_for_tables creates an empty Dataset for AutoML tables
|
|
'''
|
|
import sys
|
|
import subprocess
|
|
subprocess.run([sys.executable, '-m', 'pip', 'install', 'google-cloud-automl==0.4.0', '--quiet', '--no-warn-script-location'], env={'PIP_DISABLE_PIP_VERSION_CHECK': '1'}, check=True)
|
|
|
|
import google
|
|
from google.cloud import automl
|
|
client = automl.AutoMlClient()
|
|
|
|
location_path = client.location_path(gcp_project_id, gcp_region)
|
|
dataset_dict = {
|
|
'display_name': display_name,
|
|
'description': description,
|
|
'tables_dataset_metadata': tables_dataset_metadata,
|
|
}
|
|
dataset = client.create_dataset(
|
|
location_path,
|
|
dataset_dict,
|
|
retry or google.api_core.gapic_v1.method.DEFAULT,
|
|
timeout or google.api_core.gapic_v1.method.DEFAULT,
|
|
metadata,
|
|
)
|
|
print(dataset)
|
|
dataset_id = dataset.name.rsplit('/', 1)[-1]
|
|
return (dataset.name, dataset.create_time, dataset_id)
|
|
|
|
import json
|
|
import argparse
|
|
_missing_arg = object()
|
|
_parser = argparse.ArgumentParser(prog='Automl create dataset for tables', description='automl_create_dataset_for_tables creates an empty Dataset for AutoML tables\n')
|
|
_parser.add_argument("--gcp-project-id", dest="gcp_project_id", type=str, required=True, default=_missing_arg)
|
|
_parser.add_argument("--gcp-region", dest="gcp_region", type=str, required=True, default=_missing_arg)
|
|
_parser.add_argument("--display-name", dest="display_name", type=str, required=True, default=_missing_arg)
|
|
_parser.add_argument("--description", dest="description", type=str, required=False, default=_missing_arg)
|
|
_parser.add_argument("--tables-dataset-metadata", dest="tables_dataset_metadata", type=json.loads, required=False, default=_missing_arg)
|
|
_parser.add_argument("--retry", dest="retry", type=str, required=False, default=_missing_arg)
|
|
_parser.add_argument("--timeout", dest="timeout", type=float, required=False, default=_missing_arg)
|
|
_parser.add_argument("--metadata", dest="metadata", type=json.loads, required=False, default=_missing_arg)
|
|
_parser.add_argument("----output-paths", dest="_output_paths", type=str, nargs=3)
|
|
_parsed_args = {k: v for k, v in vars(_parser.parse_args()).items() if v is not _missing_arg}
|
|
_output_files = _parsed_args.pop("_output_paths", [])
|
|
|
|
_outputs = automl_create_dataset_for_tables(**_parsed_args)
|
|
|
|
if not hasattr(_outputs, '__getitem__') or isinstance(_outputs, str):
|
|
_outputs = [_outputs]
|
|
|
|
import os
|
|
for idx, output_file in enumerate(_output_files):
|
|
try:
|
|
os.makedirs(os.path.dirname(output_file))
|
|
except OSError:
|
|
pass
|
|
with open(output_file, 'w') as f:
|
|
f.write(str(_outputs[idx]))
|
|
image: python:3.7
|
|
inputs:
|
|
- name: gcp_project_id
|
|
type: String
|
|
- name: gcp_region
|
|
type: String
|
|
- name: display_name
|
|
type: String
|
|
- name: description
|
|
optional: true
|
|
type: String
|
|
- default: '{}'
|
|
name: tables_dataset_metadata
|
|
optional: true
|
|
type: JsonObject
|
|
- name: retry
|
|
optional: true
|
|
- name: timeout
|
|
optional: true
|
|
type: Float
|
|
- name: metadata
|
|
optional: true
|
|
type: JsonObject
|
|
name: Automl create dataset for tables
|
|
outputs:
|
|
- name: dataset_path
|
|
type: String
|
|
- name: create_time
|
|
type: String
|
|
- name: dataset_id
|
|
type: String
|