Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. automl_client = automl.AutoMlClient()
  2. prediction_client = automl.PredictionServiceClient()
  3. model_full_id = automl_client.model_path(
  4. project_id, compute_region, model_id
  5. )
  6. snippet = str(request.get_json())
  7. payload = {"text_snippet": {"content": snippet, "mime_type": "text/plain"}}
  8. response = prediction_client.predict(model_full_id, payload, params)
  9. # Set CORS headers for the preflight request
  10. if request.method == 'OPTIONS':
  11. # Allows GET requests from any origin with the Content-Type
  12. # header and caches preflight response for an 3600s
  13. headers = {
  14. 'Access-Control-Allow-Origin': '*',
  15. 'Access-Control-Allow-Methods': 'GET',
  16. 'Access-Control-Allow-Headers': 'Content-Type',
  17. 'Access-Control-Max-Age': '3600'
  18. }
  19.  
  20. return ('', 204, headers)
  21.  
  22. # Set CORS headers for the main request
  23. headers = {
  24. 'Access-Control-Allow-Origin': '*'
  25. }
  26.  
  27. return (response.data, 200, headers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement