Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Transformers Laravel Package

codewithkyrian/transformers

A Laravel-friendly transformers package for turning models, arrays, and API responses into consistent, reusable output. Define transformer classes, map fields, nest relations, and format data cleanly for JSON APIs, with minimal boilerplate and flexible customization.

View on GitHub
Deep Wiki
Context7

outline: deep

Image To Text <Badge type="tip" text="^0.3.0" />

Image to text is a computer vision task that involves extracting text from images. The task accepts image inputs and returns a text related to the content of the image. The most common applications of image to text are in Image Captioning and Optical Character Recognition (OCR).

Task ID

  • image-to-text

Default Model

  • Xenova/vit-gpt2-image-captioning

Use Cases

Image to text models find application in various scenarios, including:

  • Image Captioning: Generating textual descriptions of images for visually impaired users or for content generation.
  • Optical Character Recognition (OCR): Extracting text from images of documents, receipts, and other printed materials for digitization and indexing.
  • Content Moderation: Analyzing images for text content to filter out inappropriate or harmful content.

Running an Inference Session

Here's how to perform image to text using the pipeline:

use function Codewithkyrian\Transformers\Pipelines\pipeline;

$captioner = pipeline('image-to-text');

$result = $captioner('path/to/image.jpg');

::: details Click to view output

[
  "text" => "A close up of a cat sitting on a bed"
]

:::

The task being performed here is image captioning, determined by the model used. If you want to perform OCR, you can use a model specifically trained for that task eg. Xenova/trocr-small-handwritten, and then pass in an image of a single line of handwritten text.

Pipeline Input Options

When running the image-to-text pipeline, you can the following options:

  • texts (string)

    The image(s) to extract text from. It can be a local file path, a file resource, a URL to an image (local or remote), or an array of these inputs. It's the first argument so there's no need to pass it as a named argument.
        $result = $captioner('https://example.com/image.jpg');
    

All other options are the same as the ones in the text2text-generation pipeline, including the streamer.

Pipeline Output

The output is an array where each element corresponds to an input text and contains a key generated_text with the detected text in the image.

[
  [
    "generated_text" => "A close up of a cat sitting on a bed"
  ]
]

The number of elements in the output array corresponds to the number of input images.

Additional Notes

  • The accuracy of the extracted text depends on the quality of the input image and the model's training data.
  • The model may not be able to detect text in images with complex backgrounds, low resolution, or unusual fonts.
  • Use non-quantized models for better text extraction results.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity