Skip to content

Commit

Permalink
fix: removed Image type
Browse files Browse the repository at this point in the history
  • Loading branch information
simjak committed Feb 27, 2024
1 parent ef8a178 commit ba24460
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions coverage.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<coverage version="7.4.3" timestamp="1709057158290" lines-valid="1992" lines-covered="1309" line-rate="0.6571" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
<coverage version="7.4.3" timestamp="1709058031280" lines-valid="1992" lines-covered="1309" line-rate="0.6571" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.4.3 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
Expand Down Expand Up @@ -1066,9 +1066,9 @@
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="3" hits="1"/>
<line number="5" hits="1"/>
<line number="7" hits="1"/>
<line number="2" hits="1"/>
<line number="4" hits="1"/>
<line number="6" hits="1"/>
<line number="8" hits="1"/>
<line number="9" hits="1"/>
<line number="10" hits="1"/>
Expand Down
14 changes: 7 additions & 7 deletions semantic_router/encoders/vit.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import Any, List, Optional, Union
from typing import Any, List, Optional

from pydantic.v1 import PrivateAttr

from semantic_router.encoders import BaseEncoder
from semantic_router.utils.logger import logger

try:
from PIL.Image import Image
from PIL import Image
except ImportError:
pass
PILImage = Union[Any, "Image"]
logger.warning("Pillow is not installed. Install it with `pip install pillow`")

Check warning on line 11 in semantic_router/encoders/vit.py

View check run for this annotation

Codecov / codecov/patch

semantic_router/encoders/vit.py#L10-L11

Added lines #L10 - L11 were not covered by tests


class VitEncoder(BaseEncoder):
Expand Down Expand Up @@ -66,20 +66,20 @@ def _initialize_hf_model(self):

return processor, model

def _process_images(self, images: List[PILImage]):
def _process_images(self, images: List[Any]):
rgb_images = [self._ensure_rgb(img) for img in images]
processed_images = self._processor(images=rgb_images, return_tensors="pt")
processed_images = processed_images.to(self.device)
return processed_images

def _ensure_rgb(self, img: PILImage):
def _ensure_rgb(self, img: Any):
rgbimg = Image.new("RGB", img.size)
rgbimg.paste(img)
return rgbimg

def __call__(
self,
imgs: List[PILImage],
imgs: List[Any],
batch_size: int = 32,
) -> List[List[float]]:
all_embeddings = []
Expand Down

0 comments on commit ba24460

Please sign in to comment.