Add summary, returning probs & url

This commit is contained in:
niten 2023-03-18 18:24:59 -07:00
parent 8532b3a518
commit d4b5ecc0f9
1 changed files with 24 additions and 11 deletions

View File

@ -12,14 +12,21 @@
(get-labels! [_ image-data])
(get-detections! [_ image-data])
(get-highlights! [_ image-data])
(get-probabilities! [_ image-data]))
(get-probabilities! [_ image-data])
(get-summary! [_ image-data]))
(defn- url->string [url] (.toExternalForm url))
(defn- build-url [{:keys [scheme host port]}]
(url->string (URL. scheme host port "/images")))
(defn- send-image! [url image-bytes]
(defn- send-image! [verbose url image-bytes]
(when verbose
(println (str "sending "
(count image-bytes)
" to "
url
" for object detection")))
(let [input-stream (ByteArrayInputStream. image-bytes)]
(client/post url
{:multipart [{:name "image"
@ -39,12 +46,10 @@
:reason (:reason-phrase resp)
:response resp})))
(defn- pthru [o] (pprint o) o)
(defrecord ObjectifierClient [scheme host port]
(defrecord ObjectifierClient [scheme host port verbose]
IObjectifierClient
(get! [self image-data]
(process-response (send-image! (build-url (pthru self)) image-data)))
(process-response (send-image! verbose (build-url self) image-data)))
(get-labels! [self image-data]
(-> (get! self image-data)
@ -61,10 +66,18 @@
(get-probabilities! [self image-data]
(into {}
(map (juxt (comp keyword :label) :confidence))
(get-detections! self image-data))))
(get-detections! self image-data)))
(get-summary! [self image-data]
(let [result (get! self image-data)]
{:output (:output result)
:objects (into {}
(map (juxt (comp keyword :label) :confidence))
(get-detections! self image-data))})))
(defn define-connection
[& {:keys [scheme host port]
:or {scheme "http"
port 80}}]
(->ObjectifierClient scheme host port))
[& {:keys [scheme host port verbose]
:or {scheme "http"
port 80
verbose false}}]
(->ObjectifierClient scheme host port verbose))