def main(argv=None): """Create and train the CLV model on AutoML Tables.""" argv = sys.argv if argv is None else argv args = create_parser().parse_args(args=argv[1:]) # create and configure client keyfile_name = args.key_file client = AutoMlClient.from_service_account_file(keyfile_name) # create and deploy model model_name = create_automl_model(client, args.project_id, args.location, args.bq_dataset, args.bq_table, args.automl_dataset, args.automl_model, args.training_budget) # deploy model deploy_model(client, model_name) # get model evaluations model_evaluation = get_model_evaluation(client, model_name) # make predictions prediction_client = PredictionServiceClient.from_service_account_file( keyfile_name) do_batch_prediction(prediction_client, model_name, args.batch_gcs_input, args.batch_gcs_output)
def get_prediction(content, project_id, model_id): prediction_client = PredictionServiceClient.from_service_account_file( "AI_KEY.json") name = 'projects/{}/locations/us-central1/models/{}'.format( project_id, model_id) payload = {'image': {'image_bytes': content}} params = {} request = prediction_client.predict(name, payload, params) return request
def get_prediction(content, project_id, model_id): #storage_client = storage.Client.from_service_account_json(r"C:\Users\dell laptop\AppData\Roaming\gcloud\chicago-hospitals-social-media-7892696dfd9c.json") #credentials = service_account.Credentials.from_service_account_file("C:\\Users\\dell laptop\\AppData\\Roaming\\gcloud\\chicago-hospitals-social-media-7892696dfd9c.json") #prediction_client = automl_v1beta1.PredictionServiceClient(credentials=credentials) prediction_client = PredictionServiceClient.from_service_account_file("C:\\Users\\dell laptop\\AppData\\Roaming\\gcloud\\chicago-hospitals-social-media-7892696dfd9c.json") name = 'projects/{}/locations/us-central1/models/{}'.format(project_id, model_id) payload = {'text_snippet': {'content': content, 'mime_type': 'text/plain' }} params = {} request = prediction_client.predict(name, payload, params) return request # waits till request is returned
def get_prediction(phrase): # Create the client from the AutoML service account client = PredictionServiceClient.from_service_account_file("./hackutd-1550944892104-1ba910d00c8f.json") path = client.model_path("hackutd-1550944892104", "us-central1", "TCN6183341381162616853") # Retrieve the prediction data payload = {"text_snippet": {"content": phrase, "mime_type": "text/plain"}} request = client.predict(path, payload) # Extract the highest prediction result result = request.payload[0] data = (result.display_name, result.classification.score) return data