def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: Some value that we want to have printed later. """ # Get the input file and format. data_format = 'json' input_file = '' if args.json_instances: data_format = 'json' input_file = args.json_instances elif args.text_instances: data_format = 'text' input_file = args.text_instances # Read the instances from input file. # TODO(b/31944251): change to a generic FileType like method for # reading from input files. instances = [] if input_file == '-': instances = _ReadInstances(sys.stdin, data_format) else: with open(input_file, 'r') as f: instances = _ReadInstances(f, data_format) return predict.Predict(model_name=args.model, version_name=args.version, instances=instances)
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: Some value that we want to have printed later. """ instances = predict_utilities.ReadInstancesFromArgs( args.json_instances, args.text_instances, limit=INPUT_INSTANCES_LIMIT) model_or_version_ref = predict_utilities.ParseModelOrVersionRef( args.model, args.version) results = predict.Predict(model_or_version_ref, instances) if not args.IsSpecified('format'): # default format is based on the response. args.format = self._DefaultFormat(results.get('predictions')) return results
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: Some value that we want to have printed later. """ # Get the input instances. data_format = '' input_file = '' if args.json_instances: data_format = 'json' input_file = args.json_instances elif args.text_instances: data_format = 'text' input_file = args.text_instances instances = predict_utilities.ReadInstances(input_file, data_format) results = predict.Predict( model_name=args.model, version_name=args.version, instances=instances) # Hack to make the results available to Format() method self.predictions = results['predictions'] return results
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: Some value that we want to have printed later. """ instances = predict_utilities.ReadInstancesFromArgs( args.json_instances, args.text_instances, limit=INPUT_INSTANCES_LIMIT) model_or_version_ref = predict_utilities.ParseModelOrVersionRef( args.model, args.version) results = predict.Predict(model_or_version_ref, instances) # Hack to make the results available to Format() method self.predictions = results.get('predictions') return results