Skip to content

Commit

Permalink
Remove abstract component test (#510)
Browse files Browse the repository at this point in the history
Removing abstract component test and update image caption component
test.

Resolves #367
  • Loading branch information
mrchtr authored Oct 11, 2023
1 parent 6b46324 commit a7bbab2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 68 deletions.
15 changes: 11 additions & 4 deletions components/caption_images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime
FROM --platform=linux/amd64 pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime as base

# System dependencies
RUN apt-get update && \
Expand All @@ -15,9 +15,16 @@ ARG FONDANT_VERSION=main
RUN pip3 install fondant[aws,azure,gcp]@git+https://github.com/ml6team/fondant@${FONDANT_VERSION}

# Set the working directory to the component folder
WORKDIR /component/src
WORKDIR /component
COPY src/ src/
ENV PYTHONPATH "${PYTHONPATH}:./src"

# Copy over src-files
COPY src/ .
FROM base as test
COPY test_requirements.txt .
RUN pip3 install --no-cache-dir -r test_requirements.txt
COPY tests/ tests/
RUN python -m pytest tests

FROM base
WORKDIR /component/src
ENTRYPOINT ["fondant", "execute", "main"]
1 change: 1 addition & 0 deletions components/caption_images/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==7.4.2
38 changes: 21 additions & 17 deletions components/caption_images/tests/test_caption_images.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import pandas as pd
import requests
from caption_images.src.main import CaptionImagesComponent
from fondant.abstract_component_test import AbstractComponentTest

from src.main import CaptionImagesComponent

class TestCaptionImagesComponent(AbstractComponentTest):
def create_component(self):
return CaptionImagesComponent(

def test_image_caption_component():
image_urls = [
"https://cdn.pixabay.com/photo/2023/06/29/09/52/angkor-thom-8096092_1280.jpg",
"https://cdn.pixabay.com/photo/2023/07/19/18/56/japanese-beetle-8137606_1280.png",
]
input_dataframe = pd.DataFrame(
{"images": {"data": [requests.get(url).content for url in image_urls]}})

expected_output_dataframe = pd.DataFrame(
data={("captions", "text"): {0: "a motorcycle", 1: "a beetle"}},
)

component = CaptionImagesComponent(
model_id="Salesforce/blip-image-captioning-base",
batch_size=4,
max_new_tokens=2,
)

def create_input_data(self):
image_urls = [
"https://cdn.pixabay.com/photo/2023/06/29/09/52/angkor-thom-8096092_1280.jpg",
"https://cdn.pixabay.com/photo/2023/07/19/18/56/japanese-beetle-8137606_1280.png",
]
return pd.DataFrame(
{"images": {"data": [requests.get(url).content for url in image_urls]}},
)
output_dataframe = component.transform(input_dataframe)

def create_output_data(self):
return pd.DataFrame(
data={("captions", "text"): {0: "a motorcycle", 1: "a beetle"}},
)
pd.testing.assert_frame_equal(
left=expected_output_dataframe,
right=output_dataframe,
check_dtype=False,
)
47 changes: 0 additions & 47 deletions src/fondant/abstract_component_test.py

This file was deleted.

0 comments on commit a7bbab2

Please sign in to comment.