# processing_yield.py import json from transformers.processing_utils import ProcessorMixin class YieldProcessor(ProcessorMixin): attributes = [] valid_kwargs = [] def __init__(self, **kwargs): super().__init__() def __call__(self, inputs=None, **kwargs): """ Accept either: 1. the existing dictionary input, or 2. a JSON string containing that dictionary. """ if inputs is None: inputs = kwargs if isinstance(inputs, str): try: inputs = json.loads(inputs) except json.JSONDecodeError as e: raise ValueError( "YieldProcessor expected a JSON string " "representing the model input." ) from e if not isinstance(inputs, dict): raise ValueError( "YieldProcessor expects a dictionary or JSON string." ) return inputs