
"""simple docstring"""
import unittest

import numpy as np

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
       import tensorflow as tf

       from transformers.activations_tf import get_tf_activation







@require_tf
class 			a       (      unittest.TestCase     ):



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   tf.constant([-1_00, -1.0, -0.1, 0, 0.1, 1.0, 1_00.0]    )
  lowerCAmelCase													=   get_tf_activation('gelu'    )
  lowerCAmelCase													=   get_tf_activation('gelu_10'    )

  lowerCAmelCase													=   gelu(_snake_case    )
  lowerCAmelCase													=   geluaa(_snake_case    )

  lowerCAmelCase													=   tf.where(y_gelu_aa < 10.0							,					1.0							,					0.0    )

  self.assertEqual(tf.math.reduce_max(_snake_case    ).numpy().item()							,					10.0    )
  self.assertTrue(np.allclose(y_gelu * clipped_mask							,					y_gelu_aa * clipped_mask    )    )



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  get_tf_activation('gelu'    )
  get_tf_activation('gelu_10'    )
  get_tf_activation('gelu_fast'    )
  get_tf_activation('gelu_new'    )
  get_tf_activation('glu'    )
  get_tf_activation('mish'    )
  get_tf_activation('quick_gelu'    )
  get_tf_activation('relu'    )
  get_tf_activation('sigmoid'    )
  get_tf_activation('silu'    )
  get_tf_activation('swish'    )
  get_tf_activation('tanh'    )
  with self.assertRaises(_snake_case    ):
   get_tf_activation('bogus'    )
  with self.assertRaises(_snake_case    ):
   get_tf_activation(_snake_case    )












"""simple docstring"""
import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
       from PIL import Image







class 			a       (      unittest.TestCase      ,   a__     ):



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   load_tool('image-question-answering'    )
  self.tool.setup()
  lowerCAmelCase													=   load_tool('image-question-answering'							,					remote=_snake_case    )



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'    )    ) / '000000039769.png'    )
  lowerCAmelCase													=   self.tool(_snake_case							,					'How many cats are sleeping on the couch?'    )
  self.assertEqual(_snake_case							,					'2'    )



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'    )    ) / '000000039769.png'    )
  lowerCAmelCase													=   self.remote_tool(_snake_case							,					'How many cats are sleeping on the couch?'    )
  self.assertEqual(_snake_case							,					'2'    )



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'    )    ) / '000000039769.png'    )
  lowerCAmelCase													=   self.tool(image=_snake_case							,					question='How many cats are sleeping on the couch?'    )
  self.assertEqual(_snake_case							,					'2'    )



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'    )    ) / '000000039769.png'    )
  lowerCAmelCase													=   self.remote_tool(image=_snake_case							,					question='How many cats are sleeping on the couch?'    )
  self.assertEqual(_snake_case							,					'2'    )





