-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathask.py
More file actions
29 lines (21 loc) · 989 Bytes
/
Copy pathask.py
File metadata and controls
29 lines (21 loc) · 989 Bytes
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
"""Visual Q&A — up to 5 questions about one file, priced like a single extraction.
python examples/ask.py photo.jpg "Is there a dog in the image?" "How many people?"
"""
import sys
from visionapi import VisionAPI
if len(sys.argv) < 2:
raise SystemExit("usage: python examples/ask.py <file> [question…]")
path, *questions = sys.argv[1:]
vision = VisionAPI()
res = vision.ask(file=path, questions=questions or ["What is in this image?"])
for a in res["answers"]:
# `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.
print(f"Q: {a['question']}")
print(f"A: {a['answer']}")
print(f" verdict={a['verdict']} confidence={a['confidence']}\n")
print(
f"{res['credits_used']} credit(s) — the questions themselves are free, "
"you pay per image or per selected page."
)