



'''simple docstring'''

import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, ClassLabel, Features
from .base import TaskTemplate

@dataclass(frozen=_lowerCAmelCase )
class __snake_case(				_lowerCAmelCase ):


      '''simple docstring'''



      UpperCAmelCase							:   str									=		field(default="audio-classification"		,							metadata={"include_in_asdict_even_if_is_default": True} )
      UpperCAmelCase							:   ClassVar[Features]									=		Features({"audio": Audio()} )
      UpperCAmelCase							:   ClassVar[Features]									=		Features({"labels": ClassLabel} )
      UpperCAmelCase							:   str									=		"audio"
      UpperCAmelCase							:   str									=		"labels"


      def     __snake_case   ( self     ,	A_				)     ->     Dict:
       if self.label_column not in features:
        raise ValueError(f'Column {self.label_column} is not present in features.'				)
       if not isinstance(features[self.label_column]     ,	A_				):
        raise ValueError(f'Column {self.label_column} is not a ClassLabel.'				)
       lowerCAmelCase   =     copy.deepcopy(self				)
       lowerCAmelCase   =     self.label_schema.copy()
       lowerCAmelCase   =     features[self.label_column]
       lowerCAmelCase   =     label_schema
       return task_template




      @property
      def     __snake_case   ( self				)     ->     Dict[str, str]:
       return {
           self.audio_column: "audio",
           self.label_column: "labels",
       }




'''simple docstring'''

import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
				import torch

				from transformers import AutoModelForImageClassification

if is_vision_available():
				from transformers import AutoImageProcessor

@require_torch
@require_vision
class __snake_case(				unittest.TestCase ):


						'''simple docstring'''



						@slow
						def     __snake_case   ( self				)     ->     List[str]:
							lowerCAmelCase   =     AutoImageProcessor.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""				)
							lowerCAmelCase   =     AutoModelForImageClassification.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""				)
							model.to(A_				)

							from datasets import load_dataset

							lowerCAmelCase   =     load_dataset("""nielsr/rvlcdip-demo"""				)

							lowerCAmelCase   =     dataset["""train"""][0]["""image"""].convert("""RGB"""				)

							lowerCAmelCase   =     image_processor(A_     ,	return_tensors="""pt"""				).to(A_				)

							# forward pass
							with torch.no_grad():
								lowerCAmelCase   =     model(**A_				)
								lowerCAmelCase   =     outputs.logits

							lowerCAmelCase   =     torch.Size((1, 16)				)
							self.assertEqual(logits.shape     ,	A_				)

							lowerCAmelCase   =     torch.tensor(
							    [-0.4_1_5_8, -0.4_0_9_2, -0.4_3_4_7]     ,	device=A_     ,	dtype=torch.float     ,	)
							self.assertTrue(torch.allclose(logits[0, :3]     ,	A_     ,	atol=1e-4				)				)