Skip to content

Commit

Permalink
from_args for VQA ingredient
Browse files Browse the repository at this point in the history
  • Loading branch information
parkervg committed Oct 15, 2024
1 parent 13f94ef commit 10f56ec
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions blendsql/ingredients/builtin/vqa/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from typing import List, Tuple
from attr import attrs, attrib

from blendsql.models import Model
from blendsql._program import Program
from blendsql.ingredients.ingredient import MapIngredient
from blendsql._exceptions import IngredientException
from blendsql.ingredients.utils import partialclass


class ImageCaptionProgram(Program):
Expand All @@ -21,11 +23,17 @@ def __call__(
return ([output[0]["generated_text"].strip() for output in model_output], "")


@attrs
class ImageCaption(MapIngredient):
DESCRIPTION = """
If we need to generate a caption for an image stored in the database, we can use the scalar function to map to a new column:
`{{ImageCaption('table::column')}}`
"""
model: Model = attrib(default=None)

@classmethod
def from_args(cls, model: Model = None):
return partialclass(cls, model=model)

def run(self, model: Model, values: List[bytes], **kwargs):
"""Generates a caption for all byte images passed to it."""
Expand Down

0 comments on commit 10f56ec

Please sign in to comment.