-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathask.php
More file actions
37 lines (28 loc) · 1.12 KB
/
Copy pathask.php
File metadata and controls
37 lines (28 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/**
* Visual Q&A — up to 5 questions about one file, priced like a single extraction.
*
* php examples/ask.php photo.jpg "Is there a dog in the image?" "How many people?"
*/
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use VisionApi\Client;
if ($argc < 2) {
fwrite(STDERR, "usage: php examples/ask.php <file> [question…]\n");
exit(1);
}
$path = $argv[1];
$questions = array_slice($argv, 2) ?: ['What is in this image?'];
$vision = new Client();
$res = $vision->ask(['file' => $path, 'questions' => $questions]);
foreach ($res['answers'] as $answer) {
// `verdict` is the machine-readable half: yes | no | uncertain | n/a.
// "uncertain" is a yes/no question the image does not settle — a real answer, not a
// failure. "n/a" means it wasn't a yes/no question in the first place.
printf("Q: %s\nA: %s\n verdict=%s confidence=%s\n\n",
$answer['question'], $answer['answer'], $answer['verdict'], $answer['confidence']);
}
printf(
"%d credit(s) — the questions themselves are free, you pay per image or per selected page.\n",
$res['credits_used']
);