Example #1
0
 def test_tables_gcs_client(self):
     # The GcsClient can't currently be monkeypatched for default
     # credentials because it requires a project which can't be set.
     # Verify that creating an automl_v1beta1.GcsClient given an actual
     # storage.Client sets the client properly.
     gcs_client = storage.Client(project="xyz", credentials=_make_credentials())
     tables_gcs_client = automl_v1beta1.GcsClient(client=gcs_client)
     self.assertIs(tables_gcs_client.client, gcs_client)
Example #2
0
 def prepare_clients(self):
     print('Preparing clients ...')
     # create storage client
     self.storage_client = storage.Client(project=self.project_id)
     # create tables client
     automl_client = automl.AutoMlClient()
     tables_gcs_client = automl.GcsClient(client=self.storage_client,
                                          bucket_name=self.bucket_name)
     prediction_client = automl.PredictionServiceClient()
     self.tables_client = automl.TablesClient(
         project=self.project_id,
         region=self.bucket_region,
         client=automl_client,
         gcs_client=tables_gcs_client,
         prediction_client=prediction_client)
     print('Clients successfully created!')
    def test_init_with_project_and_credentials(self):
        # helper for checking that the storage client is initialized with the
        # passed in project and credentials.
        class FakeStorageClient:
            def __init__(self, project=None, credentials=None):
                self.project = project
                self.credentials = credentials

        patch = mock.patch("google.cloud.storage.Client", new=FakeStorageClient)
        with patch:
            credentials = AnonymousCredentials()
            gcs_client = automl_v1beta1.GcsClient(
                project=PROJECT, credentials=credentials
            )
            assert isinstance(gcs_client.client, FakeStorageClient)
            assert gcs_client.client.project == PROJECT
            assert gcs_client.client.credentials == credentials
 def gcs_client(self, bucket_name=None, client_attrs={}):
     client_mock = mock.Mock(**client_attrs)
     return automl_v1beta1.GcsClient(bucket_name=bucket_name, client=client_mock)
Example #5
0
import string

#from automlwrapper import AutoMLWrapper

# This notebook utilizes a utility script that wraps much of the AutoML Python client library, to make the code in this notebook easier to read. Feel free to check out the utility for all the details on how we are calling the underlying AutoML Client Library!

# In[2]:

# Values used for automl
PROJECT_ID = 'nlp-with-disaster-tweets'
BUCKET_NAME = 'nlp-with-disaster-tweets-lcm'

BUCKET_REGION = 'us-central1'  # Region must be us-central1

storage_client = storage.Client(project=PROJECT_ID)
tables_gcs_client = automl.GcsClient(client=storage_client,
                                     bucket_name=BUCKET_NAME)
automl_client = automl.AutoMlClient()
# Note: AutoML Tables currently is only eligible for region us-central1.
prediction_client = automl.PredictionServiceClient()
# Note: This line runs unsuccessfully without each one of these parameters
tables_client = automl.TablesClient(project=PROJECT_ID,
                                    region=BUCKET_REGION,
                                    client=automl_client,
                                    gcs_client=tables_gcs_client,
                                    prediction_client=prediction_client)

# In[3]:

# Create your GCS Bucket with your specified name and region (if it doesn't already exist)
bucket = storage.Bucket(storage_client, name=BUCKET_NAME)
if not bucket.exists():