💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Finish ImageTask functionality, part of #69
davidmezzettib81116b00f4b
diff --git a/src/python/txtai/workflow/task/base.py b/src/python/txtai/workflow/task/base.pyindex db186e83..b5daee59 100644--- a/src/python/txtai/workflow/task/base.py+++ b/src/python/txtai/workflow/task/base.py@@ -10,7 +10,7 @@ class Task:Base class for all workflow tasks."""- def __init__(self, action, select=None, unpack=True):+ def __init__(self, action=None, select=None, unpack=True):"""Creates a new task. A task defines two methods, type of data it accepts and the action to executefor each data element. Actions are callable functions.@@ -40,7 +40,7 @@ class Task:elements = [self.prepare(element) for element in elements]# Run data elements through workflow action- return self.action(elements)+ return self.action(elements) if self.action else elementsdef accept(self, element):"""diff --git a/src/python/txtai/workflow/task/image.py b/src/python/txtai/workflow/task/image.pyindex 3c908eed..6e8a63da 100644--- a/src/python/txtai/workflow/task/image.py+++ b/src/python/txtai/workflow/task/image.py@@ -2,8 +2,13 @@ImageTask module"""+import osimport re+from urllib.parse import urlparse++from PIL import Image+from .file import FileTask@@ -15,3 +20,10 @@ class ImageTask(FileTask):def accept(self, element):# Only accept file URLsreturn super().accept(element) and re.search(r"\.(gif|bmp|jpg|jpeg|png|webp)$", element.lower())++ def prepare(self, element):+ # Read image data+ url = urlparse(element)+ path = os.path.abspath(os.path.join(url.netloc, url.path))++ return Image.open(path)