Advertisement
Caio_25

Predict Deployed Model

Dec 10th, 2021
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. from oauth2client.client import GoogleCredentials
  2. from googleapiclient import discovery
  3. from googleapiclient import errors
  4. from google.api_core.client_options import ClientOptions
  5. # Store your full project ID in a variable in the format the API needs.
  6. project_id = 'projects/{}'.format('imageeditorbackend')
  7.  
  8. prefix = "{}-ml".format('us-east1')
  9. api_endpoint = "https://{}.googleapis.com".format(prefix)
  10. client_options = ClientOptions(api_endpoint=api_endpoint)
  11. #service = googleapiclient.discovery.build('ml', 'v1', client_options=client_options)
  12. # Build a representation of the Cloud ML API.
  13. ml = discovery.build('ml', 'v1', client_options=client_options)
  14.  
  15. project = 'imageeditorbackend'
  16. model = 'modelo_teste'
  17. name = 'projects/{}/models/{}'.format(project, model)
  18. instances = [
  19. [56, "housemaid", "married", "basic.4y", "no", "no", "no", "telephone", "may", "mon", 261, 1, 999, 0, "nonexistent", 1.1, 93.994, -36.4, 4.857, 5191, "no"]
  20. ]
  21.  
  22. # Create a dictionary with the fields from the request body.
  23. request_dict = {'name': name,
  24.         'body':{'instances': instances}
  25. }
  26.  
  27. # Create a request to call projects.models.create.
  28. request = ml.projects().predict(
  29.     name=name,
  30.     body={'instances': instances}
  31. )
  32.  
  33. # Make the call.
  34. try:
  35.     response = request.execute()
  36.     print(response)
  37. except error:
  38.     # Something went wrong, print out some information.
  39.     print('There was an error creating the model. Check the details:')
  40.     print(error)
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement