H4T3D

algo

Apr 25th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. function mood_detection($image , $no_results){
  2.  
  3. // get your API Key at https://algorithmia.com/user#credentials
  4. $api_key = 'sim18SC3i39RSf8olp5SkmmnquD1';
  5.  
  6. // pick an algorithm at https://algorithmia.com/algorithms -- and append a version number
  7. $algorithm = 'deeplearning/EmotionRecognitionCNNMBP/1.0.1';
  8.  
  9. // most algorithms accept JSON Objects https://i.imgflip.com/vh6to.jpg
  10. $data = array('image' => $image , 'numResults' => $no_results );
  11. $data_json = json_encode($data);
  12.  
  13. // prepare cURL to algorithm endpoint
  14. $ch = curl_init();
  15. $headers = array(
  16. 'Content-Type: application/json',
  17. 'Authorization: Simple ' . $api_key,
  18. 'Content-Length: ' . strlen($data_json)
  19. );
  20. curl_setopt_array($ch, array(
  21. CURLOPT_URL => 'https://api.algorithmia.com/v1/algo/' . $algorithm,
  22. CURLOPT_HTTPHEADER => $headers,
  23. CURLOPT_POSTFIELDS => $data_json,
  24. CURLOPT_RETURNTRANSFER => true,
  25. CURLOPT_POST => true
  26. ));
  27.  
  28. // run the algorithm and get the results (usually a JSON-encoded string)
  29. $response_json = curl_exec($ch);
  30. curl_close($ch);
  31. $response = json_decode($response_json, true);
  32.  
  33. return $response;
  34.  
  35. }
Add Comment
Please, Sign In to add comment