Created
May 22, 2019 17:33
-
-
Save newbold/cc9505f5ad1e2665af67947493c5fdb7 to your computer and use it in GitHub Desktop.
Simple Watson Visual Recognition implementation with Twilio MMS in PHP. Twilio will POST an image URL through via MediaUrl0, so it's easy to grab that and send it on to Watson for recognition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(isset($_REQUEST['MediaUrl0'])) { | |
$img = $_REQUEST['MediaUrl0']; | |
$apikey = 'put_a_real_key_here'; | |
$data = `curl -u "apikey:$apikey" "https://gateway.watsonplatform.net/visual-recognition/api/v3/classify?url=$img&version=2018-03-19"`; | |
$data = json_decode($data); | |
$thing = $data->images[0]->classifiers[0]->classes[0]->class; | |
$intros = array('Hey', 'Cool', 'Jeepers', 'Wow', 'Awesome', 'Nifty', 'Woah', 'Yikes', 'Well', 'Eh', 'Um', 'Uh', 'Zoinks'); | |
$intro = array_rand($intros); | |
$intro = $intros[$intro]; | |
$vowels = array('a','e','i','o','u'); | |
if(in_array($thing{0}, $vowels)) $article = 'an'; | |
else $article = 'a'; | |
echo '<?xml version="1.0" encoding="UTF-8"?> | |
<Response> | |
<Message>'.$intro.', that looks like '.$article.' '.$thing.'.</Message> | |
</Response>'; | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment