Guest User

Untitled

a guest
Jan 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import sys
  2.  
  3. from google.cloud import automl_v1beta1
  4. from google.cloud.automl_v1beta1.proto import service_pb2
  5.  
  6.  
  7. def get_prediction(content, project_id, model_id):
  8. prediction_client = automl_v1beta1.PredictionServiceClient()
  9.  
  10. name = 'projects/{}/locations/us-central1/models/{}'.format(project_id, model_id)
  11. payload = {'image': {'image_bytes': content }}
  12. params = {}
  13. request = prediction_client.predict(name, payload, params)
  14. return request # waits till request is returned
  15.  
  16. if __name__ == '__main__':
  17. file_path = sys.argv[1]
  18. project_id = sys.argv[2]
  19. model_id = sys.argv[3]
  20.  
  21. with open(file_path, 'rb') as ff:
  22. content = ff.read()
  23.  
  24. print get_prediction(content, project_id, model_id)
Add Comment
Please, Sign In to add comment