Giter VIP home page Giter VIP logo

sight-clojure's Introduction

Clojars Project Clojure CI

This repository contains the official Sight API Clojure client. The Sight API is a text recognition service.

Quickstart

  1. Add this project as a dependency.

Leiningen/Boot:

[sight "1.1.0"]

Clojure CLI/deps.edn:

sight {:mvn/version "1.1.0"}

Gradle

compile 'sight:sight:1.1.0

Maven

<dependency>
  <groupId>sight</groupId>
  <artifactId>sight</artifactId>
  <version>1.1.0</version>
</dependency>
  1. Require or import the package. For example, add it to :require:
(ns my-namespace
  ...
  (:require [sight.core :as sight]))
  1. Grab an API key from the Sight dashboard.
  2. Create a client, passing your API key into the constructor, and recognize text:
(let [client (sight/->Client "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
      files  ["invoice.pdf" "receipt.png"]]
  (sight/recognize client files))

The returned value of (sight/recognize client files) looks like this:

{:pages [{:error "",
          :file-index 0,
          :page-number 1,
          :number-of-pages-in-file 1,
          :recognized-text [{:top-left-y 193,
                             :bottom-right-y 243,
                             :bottom-left-x 152,
                             :top-right-x 500,
                             :bottom-left-y 248,
                             :top-right-y 188,
                             :top-left-x 151,
                             :bottom-right-x 501,
                             :confidence 0.10092532855610954,
                             :text "Dummy PDF file"}]}]}

Word-Level Bounding Boxes

recognize has an additional signature with a third parameter, word-level-bounding-boxes. If it's true then word-level bounding boxes are returned instead of sentence-level bounding boxes. E.g.,

(sight/recognize client (list "invoice.pdf" "receipt.png") true)
(sight/recognize client (list "invoice.pdf" "receipt.png") true)

Streaming Results as Pages are Processed

When (sight/recognize ...) is called, it polls a URL and aggregates the results over time. Finally, when all results are collected, the function returns.

It is possible to use results immediately as they come in, instead of waiting for all results to be collected. To do this, use the recognize-stream function.

The recognize-stream uses Adam Bard's Failjure library: Instead of throwing exceptions, recognize-stream returns a failjure/failure.

Example

Users must define failure-func and success-func in the following code snippet:

(:require [failjure.core :as f])

(defn process [pages]
  (->> pages
    (map (fn [p]
      (if (f/failed? p)
        (failure-func (f/message p))
        (success-func p)))))

(let [client (->Client "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]
  (->> (recognize-stream client (list "receipt.pdf" "invoice.png"))
    (run! process)))

Official API Documentation

Here is the official documentation for the Sight API.

Apache V2 License

This code is licensed under Apache V2.0. The full text of the license can be found in the "LICENSE" file.

Lead Maintainer

Contributors

sight-clojure's People

Contributors

ashwinbhaskar avatar siftrics avatar

Stargazers

Hamzah Chaudhry avatar Jinmo Im avatar Olim Saidov avatar  avatar Stathis Sideris avatar  avatar Oleg Martynov avatar Josef Pospíšil avatar Александар Симић avatar Vitaly Kornilov avatar  avatar Dmitri Sotnikov avatar Gert Goet avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

ashwinbhaskar

sight-clojure's Issues

Add tests

The code lacks tests (no tests, actually). Tests need to be added so that lot of regression bugs can be caught. And CI pipeline can be setup which comes free with github/travis ci for open source projects

Stream pages as they are fetched

Right now the client fetches all the pages and gives them to the caller at one shot. This could be a waste of time and resources if the doesn't need to wait for all the pages for them to start processing.
Need to introduce a function which will return the pages as they are fetched from the polling URL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.