

from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import numpy
	import tensorflow as tf

	from transformers import (
	    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
	    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
	    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
	    BertConfig,
	    DPRConfig,
	    TFDPRContextEncoder,
	    TFDPRQuestionEncoder,
	    TFDPRReader,
	)



class    _a						:


					'''simple docstring'''






					def __init__(			self   ,	A__   ,	A__=13   ,	A__=7   ,	A__=True   ,	A__=True   ,	A__=True   ,	A__=True   ,	A__=99   ,	A__=32   ,	A__=2   ,	A__=4   ,	A__=37   ,	A__="gelu"   ,	A__=0.1   ,	A__=0.1   ,	A__=512   ,	A__=16   ,	A__=2   ,	A__=0.0_2   ,	A__=3   ,	A__=4   ,	A__=None   ,	A__=0   ,	):
						A__							:   Optional[int]					       =		parent
						A__							:   List[str]					       =		batch_size
						A__							:   Optional[int]					       =		seq_length
						A__							:   str					       =		is_training
						A__							:   int					       =		use_input_mask
						A__							:   Optional[Any]					       =		use_token_type_ids
						A__							:   Union[str, Any]					       =		use_labels
						A__							:   Dict					       =		vocab_size
						A__							:   int					       =		hidden_size
						A__							:   List[str]					       =		num_hidden_layers
						A__							:   List[str]					       =		num_attention_heads
						A__							:   str					       =		intermediate_size
						A__							:   Optional[int]					       =		hidden_act
						A__							:   Any					       =		hidden_dropout_prob
						A__							:   Union[str, Any]					       =		attention_probs_dropout_prob
						A__							:   Dict					       =		max_position_embeddings
						A__							:   Tuple					       =		type_vocab_size
						A__							:   Optional[Any]					       =		type_sequence_label_size
						A__							:   Any					       =		initializer_range
						A__							:   Tuple					       =		num_labels
						A__							:   Optional[Any]					       =		num_choices
						A__							:   str					       =		scope
						A__							:   Dict					       =		projection_dim






					def   __A      (			self      ):
						A__							:   Any					       =		ids_tensor([self.batch_size, self.seq_length]   ,	self.vocab_size      )

						A__							:   Union[str, Any]					       =		None
						if self.use_input_mask:
							# follow test_modeling_tf_ctrl.py
							A__							:   int					       =		random_attention_mask([self.batch_size, self.seq_length]      )

						A__							:   str					       =		None
						if self.use_token_type_ids:
							A__							:   str					       =		ids_tensor([self.batch_size, self.seq_length]   ,	self.type_vocab_size      )

						A__							:   Tuple					       =		None
						A__							:   int					       =		None
						A__							:   List[Any]					       =		None
						if self.use_labels:
							A__							:   Union[str, Any]					       =		ids_tensor([self.batch_size]   ,	self.type_sequence_label_size      )
							A__							:   List[Any]					       =		ids_tensor([self.batch_size, self.seq_length]   ,	self.num_labels      )
							A__							:   str					       =		ids_tensor([self.batch_size]   ,	self.num_choices      )

						A__							:   Any					       =		BertConfig(
						    vocab_size=self.vocab_size   ,	hidden_size=self.hidden_size   ,	num_hidden_layers=self.num_hidden_layers   ,	num_attention_heads=self.num_attention_heads   ,	intermediate_size=self.intermediate_size   ,	hidden_act=self.hidden_act   ,	hidden_dropout_prob=self.hidden_dropout_prob   ,	attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,	max_position_embeddings=self.max_position_embeddings   ,	type_vocab_size=self.type_vocab_size   ,	is_decoder=__lowerCAmelCase   ,	initializer_range=self.initializer_range   ,	)
						A__							:   str					       =		DPRConfig(projection_dim=self.projection_dim   ,	**config.to_dict()      )

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






					def   __A      (			self   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__      ):
						A__							:   str					       =		TFDPRContextEncoder(config=__lowerCAmelCase      )
						A__							:   Union[str, Any]					       =		model(__lowerCAmelCase   ,	attention_mask=__lowerCAmelCase   ,	token_type_ids=__lowerCAmelCase      )
						A__							:   Tuple					       =		model(__lowerCAmelCase   ,	token_type_ids=__lowerCAmelCase      )
						A__							:   List[Any]					       =		model(__lowerCAmelCase      )
						self.parent.assertEqual(result.pooler_output.shape   ,	(self.batch_size, self.projection_dim or self.hidden_size)      )






					def   __A      (			self   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__      ):
						A__							:   int					       =		TFDPRQuestionEncoder(config=__lowerCAmelCase      )
						A__							:   Optional[int]					       =		model(__lowerCAmelCase   ,	attention_mask=__lowerCAmelCase   ,	token_type_ids=__lowerCAmelCase      )
						A__							:   List[Any]					       =		model(__lowerCAmelCase   ,	token_type_ids=__lowerCAmelCase      )
						A__							:   Optional[int]					       =		model(__lowerCAmelCase      )
						self.parent.assertEqual(result.pooler_output.shape   ,	(self.batch_size, self.projection_dim or self.hidden_size)      )






					def   __A      (			self   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__      ):
						A__							:   List[Any]					       =		TFDPRReader(config=__lowerCAmelCase      )
						A__							:   List[Any]					       =		model(__lowerCAmelCase   ,	attention_mask=__lowerCAmelCase      )

						self.parent.assertEqual(result.start_logits.shape   ,	(self.batch_size, self.seq_length)      )
						self.parent.assertEqual(result.end_logits.shape   ,	(self.batch_size, self.seq_length)      )
						self.parent.assertEqual(result.relevance_logits.shape   ,	(self.batch_size,)      )






					def   __A      (			self      ):
						A__							:   List[Any]					       =		self.prepare_config_and_inputs()
						(
						    (
						    A__       
						)       ,       (
						    A__       
						)       ,       (
						    A__       
						)       ,       (
						    A__       
						)       ,       (
						    A__       
						)       ,       (
						    A__       
						)       ,       (
						    A__       
						)       ,              
						)							:   Tuple					       =		config_and_inputs
						A__							:   Dict					       =		{"""input_ids""": input_ids}
						return config, inputs_dict



@require_tf
class    _a						(_a		,       _a		,       unittest.TestCase    ):


					'''simple docstring'''






					UpperCAmelCase__:       List[str]  							=	(
					    (
					        TFDPRContextEncoder,
					        TFDPRQuestionEncoder,
					        TFDPRReader,
					    )
					    if is_tf_available()
					    else ()
					)
					UpperCAmelCase__:       Optional[Any]  							=	{"""feature-extraction""": TFDPRQuestionEncoder} if is_tf_available() else {}

					UpperCAmelCase__:       str  							=	False
					UpperCAmelCase__:       Optional[int]  							=	False
					UpperCAmelCase__:       Any  							=	False
					UpperCAmelCase__:       Optional[int]  							=	False
					UpperCAmelCase__:       List[Any]  							=	False






					def   __A      (			self      ):
						A__							:   Optional[Any]					       =		TFDPRModelTester(self      )
						A__							:   Optional[Any]					       =		ConfigTester(self   ,	config_class=__lowerCAmelCase   ,	hidden_size=37      )






					def   __A      (			self      ):
						self.config_tester.run_common_tests()






					def   __A      (			self      ):
						A__							:   Optional[int]					       =		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_dpr_context_encoder(*__lowerCAmelCase      )






					def   __A      (			self      ):
						A__							:   List[str]					       =		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_dpr_question_encoder(*__lowerCAmelCase      )






					def   __A      (			self      ):
						A__							:   Tuple					       =		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_dpr_reader(*__lowerCAmelCase      )






					@slow
					def   __A      (			self      ):
						for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							A__							:   str					       =		TFDPRContextEncoder.from_pretrained(__lowerCAmelCase      )
							self.assertIsNotNone(__lowerCAmelCase      )

						for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							A__							:   List[Any]					       =		TFDPRContextEncoder.from_pretrained(__lowerCAmelCase      )
							self.assertIsNotNone(__lowerCAmelCase      )

						for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							A__							:   Union[str, Any]					       =		TFDPRQuestionEncoder.from_pretrained(__lowerCAmelCase      )
							self.assertIsNotNone(__lowerCAmelCase      )

						for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							A__							:   str					       =		TFDPRReader.from_pretrained(__lowerCAmelCase      )
							self.assertIsNotNone(__lowerCAmelCase      )



@require_tf
class    _a						(unittest.TestCase    ):


					'''simple docstring'''






					@slow
					def   __A      (			self      ):
						A__							:   Tuple					       =		TFDPRQuestionEncoder.from_pretrained("""facebook/dpr-question_encoder-single-nq-base"""      )

						A__							:   Optional[int]					       =		tf.constant(
						    [[101, 7592, 1010, 2003, 2026, 3899, 1_0140, 1029, 102]]      )  # [CLS] hello, is my dog cute? [SEP]
						A__							:   Optional[Any]					       =		model(__lowerCAmelCase      )[0]  # embedding shape = (1, 768)
						# compare the actual values for a slice.
						A__							:   str					       =		tf.constant(
						    [
						        [
						            0.0_3_2_3_6_2_5_3,
						            0.1_2_7_5_3_3_3_5,
						            0.1_6_8_1_8_5_0_9,
						            0.0_0_2_7_9_7_8_6,
						            0.3_8_9_6_9_3_3,
						            0.2_4_2_6_4_9_4_5,
						            0.2_1_7_8_9_7_1,
						            -0.0_2_3_3_5_2_2_7,
						            -0.0_8_4_8_1_9_5_9,
						            -0.1_4_3_2_4_1_1_7,
						        ]
						    ]      )
						self.assertTrue(numpy.allclose(output[:, :10].numpy()   ,	expected_slice.numpy()   ,	atol=1e-4      )      )






import requests

A_	:			List[Any]  	=      'YOUR API KEY'

def 						UpperCamelCase (lowercase_:			str   ,				lowercase_:			str = giphy_api_key )					->				list:
	A__							:   Dict					       =		"""+""".join(query.split() )
	A__							:   Optional[int]					       =		f"""https://api.giphy.com/v1/gifs/search?q={formatted_query}&api_key={api_key}"""
	A__							:   Any					       =		requests.get(lowercase_ ).json()["""data"""]
	return [gif["url"] for gif in gifs]


if __name__ == "__main__":
	print('\n'.join(get_gifs('space ship')))



