Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mood_detection($image , $no_results){
- // get your API Key at https://algorithmia.com/user#credentials
- $api_key = 'sim18SC3i39RSf8olp5SkmmnquD1';
- // pick an algorithm at https://algorithmia.com/algorithms -- and append a version number
- $algorithm = 'deeplearning/EmotionRecognitionCNNMBP/1.0.1';
- // most algorithms accept JSON Objects https://i.imgflip.com/vh6to.jpg
- $data = array('image' => $image , 'numResults' => $no_results );
- $data_json = json_encode($data);
- // prepare cURL to algorithm endpoint
- $ch = curl_init();
- $headers = array(
- 'Content-Type: application/json',
- 'Authorization: Simple ' . $api_key,
- 'Content-Length: ' . strlen($data_json)
- );
- curl_setopt_array($ch, array(
- CURLOPT_URL => 'https://api.algorithmia.com/v1/algo/' . $algorithm,
- CURLOPT_HTTPHEADER => $headers,
- CURLOPT_POSTFIELDS => $data_json,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POST => true
- ));
- // run the algorithm and get the results (usually a JSON-encoded string)
- $response_json = curl_exec($ch);
- curl_close($ch);
- $response = json_decode($response_json, true);
- return $response;
- }
Add Comment
Please, Sign In to add comment