codingutf8 2023 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license processor class for tvlt attributes imageprocessor featureextractor imageprocessorclass tvltimageprocessor featureextractorclass tvltfeatureextractor def initself imageprocessor featureextractor super initimageprocessorimageprocessor featureextractorfeatureextractor self imageprocessor imageprocessor self featureextractor featureextractor def call self imagesnone audionone imagesmixednone samplingratenone maskaudiofalse maskpixelfalse args kwargs if images is none and audio is none raise valueerroryou need to specify either an images or audio input to process imagesmixeddict none if images is not none imagesdict self imageprocessorimages maskpixelmaskpixel args kwargs if imagesmixed is not none imagesmixeddict self imageprocessorimagesmixed ismixedtrue args kwargs if audio is not none audiodict self featureextractor audio args samplingratesamplingrate maskaudiomaskaudio kwargs outputdict if audio is not none outputdict updateaudiodict if images is not none outputdict updateimagesdict if imagesmixeddict is not none outputdict updateimagesmixeddict return outputdict property def modelinputnamesself imageprocessorinputnames self imageprocessor modelinputnames featureextractorinputnames self featureextractor modelinputnames return listdict fromkeysimageprocessorinputnames featureextractorinputnames coding utf 8 2023 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license processor class for tvlt constructs a tvlt processor which wraps a tvlt image processor and tvlt feature extractor into a single processor tvltprocessor offers all the functionalities of tvltimageprocessor and tvltfeatureextractor see the docstring of tvltprocessor __call__ for more information args image_processor tvltimageprocessor an instance of tvltimageprocessor the image processor is a required input feature_extractor tvltfeatureextractor an instance of tvltfeatureextractor the feature extractor is a required input forwards the images argument to tvltimageprocessor s tvltimageprocessor preprocess and the audio argument to tvltfeatureextractor s tvltfeatureextractor __call__ please refer to the docstring of the above two methods for more information
from ...processing_utils import ProcessorMixin


class TvltProcessor(ProcessorMixin):
    r

    attributes = ["image_processor", "feature_extractor"]
    image_processor_class = "TvltImageProcessor"
    feature_extractor_class = "TvltFeatureExtractor"

    def __init__(self, image_processor, feature_extractor):
        super().__init__(image_processor=image_processor, feature_extractor=feature_extractor)

        self.image_processor = image_processor
        self.feature_extractor = feature_extractor

    def __call__(
        self,
        images=None,
        audio=None,
        images_mixed=None,
        sampling_rate=None,
        mask_audio=False,
        mask_pixel=False,
        *args,
        **kwargs,
    ):
        

        if images is None and audio is None:
            raise ValueError("You need to specify either an `images` or `audio` input to process.")

        images_mixed_dict = None
        if images is not None:
            images_dict = self.image_processor(images, mask_pixel=mask_pixel, *args, **kwargs)
        if images_mixed is not None:
            images_mixed_dict = self.image_processor(images_mixed, is_mixed=True, *args, **kwargs)
        if audio is not None:
            audio_dict = self.feature_extractor(
                audio, *args, sampling_rate=sampling_rate, mask_audio=mask_audio, **kwargs
            )

        output_dict = {}
        if audio is not None:
            output_dict.update(audio_dict)
        if images is not None:
            output_dict.update(images_dict)
        if images_mixed_dict is not None:
            output_dict.update(images_mixed_dict)
        return output_dict

    @property
    def model_input_names(self):
        image_processor_input_names = self.image_processor.model_input_names
        feature_extractor_input_names = self.feature_extractor.model_input_names
        return list(dict.fromkeys(image_processor_input_names + feature_extractor_input_names))