Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- automl_client = automl.AutoMlClient()
- prediction_client = automl.PredictionServiceClient()
- model_full_id = automl_client.model_path(
- project_id, compute_region, model_id
- )
- snippet = str(request.get_json())
- payload = {"text_snippet": {"content": snippet, "mime_type": "text/plain"}}
- response = prediction_client.predict(model_full_id, payload, params)
- # Set CORS headers for the preflight request
- if request.method == 'OPTIONS':
- # Allows GET requests from any origin with the Content-Type
- # header and caches preflight response for an 3600s
- headers = {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Methods': 'GET',
- 'Access-Control-Allow-Headers': 'Content-Type',
- 'Access-Control-Max-Age': '3600'
- }
- return ('', 204, headers)
- # Set CORS headers for the main request
- headers = {
- 'Access-Control-Allow-Origin': '*'
- }
- return (response.data, 200, headers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement