npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tesseract-ocr-golem

v1.2.2

Published

Tesseract OCR library that executes the OCR on the Golem Network scaling to thousands of CPUs

Downloads

60

Readme

Tesseract OCR on Golem

OCR Images using Tesseract by leveraging Golem Network's computation resources.

Features

  • 🔍 Runs Tesseract OCR on files which you provide to convertImageToText method.
  • 🌐 Leverages Golem Network's computing capacity
  • 💰 Simplifies pricing for compute resources you provide the specification of your needs with the minimum amount of input required.
  • Scales resources dynamically
    • Acquires compute resources and scales up the number of OCR instances in response to the request load to a configured maximum.
    • Releases compute resources unused for at least 30 seconds, down-scaling automatically for cost-saving.

Installation

Installing Tesseract OCR on Golem library

You can install this library using your favourite package manager:

npm install --save tesseract-ocr-golem

Joining the Golem Network as requestor

In order to run workloads on Golem Network, you need to join as a requestor. If you're working on a linux system, it's a simple bash-line. For more installation instructions, visit the Official JS SDK QuickStart.

curl -sSf https://join.golem.network/as-requestor | bash -

After installing Golem Network software (yagna), you can obtain your API key which you will use with the library:

yagna app-key list

Usage

Here's an example of a working script that will allow you to send example images to OCR on the Golem Network using Tesseract OCR image.

import * as fs from "fs";
import { TesseractOcrOnGolem } from "tesseract-ocr-golem";

/**
 * Utility used to write down results
 *
 * @param text The resulting text if any present
 */
const writeTextToResultFile = (text?: string) => {
  if (text) {
    fs.writeFileSync(`./examples/out/results.txt`, text, { flag: "a" });
  }
};

(async () => {
  const ocr = new TesseractOcrOnGolem({
    service: {
      market: {
        rentHours: 0.5,
        priceGlmPerHour: 1.0,
      },
      deploy: {
        maxReplicas: 4,
        resources: {
          minCpuThreads: 2,
          maxCpuThreads: 4,
        },
        downscaleIntervalSec: 60,
      },
      initTimeoutSec: 90,
      requestStartTimeoutSec: 30,
    },
    args: {
      lang: "eng",
    },
  });

  try {
    // Power-on the OCR, get the resources on Golem Network
    // This will wait until the resources are found and the OCR is ready to use
    await ocr.init();

    // Do your work
    console.log("Starting work for my customers...");
    const texts = await Promise.all([
      ocr.convertImageToText("./examples/data/img.png"),
      ocr.convertImageToText("./examples/data/5W40s.png"),
      ocr.convertImageToText("./examples/data/msword_text_rendering.png"),
      ocr.convertImageToText("./examples/data/poem.png"),
    ]);

    texts.forEach(writeTextToResultFile);

    console.log("Work done, going to bill my customers...");
    // TODO: Bill your customers ;)
  } catch (err) {
    console.error(err, "Failed to run the OCR on Golem");
  } finally {
    await ocr.shutdown();
  }
})().catch((err) => console.error(err, "Error in main"));

Configuration

Supported environment variables

Operating on the Golem Network requires

| Env variable | Required | Default value | Description | | ----------------------- | -------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | GOLEM_API_KEY | yes | | Yagna app-key used to identify your application | | GOLEM_API_URL | no | http://localhost:7465 | Where is your yagna instance located | | GOLEM_PAYMENT_NETWORK | no | holesky | On which network you want to get the compute resources. polygon is the main network, where the real GLM tokens are used. holesky is the default test network. |

The configuration object

The config object accepted by TesseractOcrOnGolem can be composed of 2 properties:

  • args which control the default parameters which will be passed to tesseract when running the OCR (see docs)
  • service which control the deployment of the OCR instances on the Golem Network (see docs)

For details regarding specific config options, please refer to the API Documentation.

Debugging

If you want to know what's going on inside the library, including logs from @golem-sdk/golem-js you can use the DEBUG environment variable to see verbose logs. This library makes use of the debug package to implement logs. If you want to fine-tune the log output, please refer to the library's documentation.

Most of the time, such a line should suffice:

DEBUG="golem-js:*,golem,tesseract" GOLEM_API_KEY="your-api-key-to-yagna" npm run example

See also