
'''simple docstring'''

import unittest

from transformers import (
    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    TextClassificationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_tf, require_torch, slow

from .test_pipelines_common import ANY


# These 2 model types require different inputs than those of the usual text models.
UpperCAmelCase__ :			Optional[int]											=		{"LayoutLMv2Config", "LayoutLMv3Config"}






@is_pipeline_test
class  A  (						unittest.TestCase     ):
	snake_case__   :Union[str, Any]   =  MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
	snake_case__   :Optional[Any]   =  TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

	if model_mapping is not None:
		snake_case__   :List[str]   =  {config: model for config, model in model_mapping.items() if config.__name__ not in _TO_SKIP}
	if tf_model_mapping is not None:
		snake_case__   :Dict   =  {
		    config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
		}





	@require_torch
	def 				__SCREAMING_SNAKE_CASE	(       self      :							Union[str, Any]				):


				"""simple docstring"""

				lowerCAmelCase__										=				pipeline(
				    task="text-classification"   ,				model="hf-internal-testing/tiny-random-distilbert"   ,				framework="pt"				)

				lowerCAmelCase__										=				text_classifier("This is great !"				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "LABEL_0", "score": 0.504}]				)

				lowerCAmelCase__										=				text_classifier("This is great !"   ,				top_k=2				)
				self.assertEqual(
				    nested_simplify(__magic_name__				)   ,				[{"label": "LABEL_0", "score": 0.504}, {"label": "LABEL_1", "score": 0.496}]				)

				lowerCAmelCase__										=				text_classifier(["This is great !", "This is bad"]   ,				top_k=2				)
				self.assertEqual(
				    nested_simplify(__magic_name__				)   ,				[
				        [{"label": "LABEL_0", "score": 0.504}, {"label": "LABEL_1", "score": 0.496}],
				        [{"label": "LABEL_0", "score": 0.504}, {"label": "LABEL_1", "score": 0.496}],
				    ]   ,				)

				lowerCAmelCase__										=				text_classifier("This is great !"   ,				top_k=1				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "LABEL_0", "score": 0.504}]				)

				# Legacy behavior
				lowerCAmelCase__										=				text_classifier("This is great !"   ,				return_all_scores=__magic_name__				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "LABEL_0", "score": 0.504}]				)

				lowerCAmelCase__										=				text_classifier("This is great !"   ,				return_all_scores=__magic_name__				)
				self.assertEqual(
				    nested_simplify(__magic_name__				)   ,				[[{"label": "LABEL_0", "score": 0.504}, {"label": "LABEL_1", "score": 0.496}]]				)

				lowerCAmelCase__										=				text_classifier(["This is great !", "Something else"]   ,				return_all_scores=__magic_name__				)
				self.assertEqual(
				    nested_simplify(__magic_name__				)   ,				[
				        [{"label": "LABEL_0", "score": 0.504}, {"label": "LABEL_1", "score": 0.496}],
				        [{"label": "LABEL_0", "score": 0.504}, {"label": "LABEL_1", "score": 0.496}],
				    ]   ,				)

				lowerCAmelCase__										=				text_classifier(["This is great !", "Something else"]   ,				return_all_scores=__magic_name__				)
				self.assertEqual(
				    nested_simplify(__magic_name__				)   ,				[
				        {"label": "LABEL_0", "score": 0.504},
				        {"label": "LABEL_0", "score": 0.504},
				    ]   ,				)





	@require_torch
	def 				__SCREAMING_SNAKE_CASE	(       self      :							Dict				):


				"""simple docstring"""

				import torch

				lowerCAmelCase__										=				pipeline(
				    task="text-classification"   ,				model="hf-internal-testing/tiny-random-distilbert"   ,				framework="pt"   ,				device=torch.device("cpu"				)   ,				)

				lowerCAmelCase__										=				text_classifier("This is great !"				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "LABEL_0", "score": 0.504}]				)





	@require_tf
	def 				__SCREAMING_SNAKE_CASE	(       self      :							Union[str, Any]				):


				"""simple docstring"""

				lowerCAmelCase__										=				pipeline(
				    task="text-classification"   ,				model="hf-internal-testing/tiny-random-distilbert"   ,				framework="tf"				)

				lowerCAmelCase__										=				text_classifier("This is great !"				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "LABEL_0", "score": 0.504}]				)





	@slow
	@require_torch
	def 				__SCREAMING_SNAKE_CASE	(       self      :							Any				):


				"""simple docstring"""

				lowerCAmelCase__										=				pipeline("text-classification"				)

				lowerCAmelCase__										=				text_classifier("This is great !"				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "POSITIVE", "score": 1.0}]				)
				lowerCAmelCase__										=				text_classifier("This is bad !"				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "NEGATIVE", "score": 1.0}]				)
				lowerCAmelCase__										=				text_classifier("Birds are a type of animal"				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "POSITIVE", "score": 0.988}]				)





	@slow
	@require_tf
	def 				__SCREAMING_SNAKE_CASE	(       self      :							List[str]				):


				"""simple docstring"""

				lowerCAmelCase__										=				pipeline("text-classification"   ,				framework="tf"				)

				lowerCAmelCase__										=				text_classifier("This is great !"				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "POSITIVE", "score": 1.0}]				)
				lowerCAmelCase__										=				text_classifier("This is bad !"				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "NEGATIVE", "score": 1.0}]				)
				lowerCAmelCase__										=				text_classifier("Birds are a type of animal"				)
				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": "POSITIVE", "score": 0.988}]				)





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Any   ,				__magic_name__      :							Union[str, Any]   ,				__magic_name__      :							Union[str, Any]   ,				__magic_name__      :							List[str]				):


				"""simple docstring"""

				lowerCAmelCase__										=				TextClassificationPipeline(model=__magic_name__   ,				tokenizer=__magic_name__				)
				return text_classifier, ["HuggingFace is in", "This is another test"]







	def 				__SCREAMING_SNAKE_CASE	(       self      :							Dict   ,				__magic_name__      :							Any   ,				__magic_name__      :							Union[str, Any]				):


				"""simple docstring"""

				lowerCAmelCase__										=				text_classifier.model
				# Small inputs because BartTokenizer tiny has maximum position embeddings = 22
				lowerCAmelCase__										=				"HuggingFace is in"
				lowerCAmelCase__										=				text_classifier(__magic_name__				)

				self.assertEqual(nested_simplify(__magic_name__				)   ,				[{"label": ANY(__magic_name__				), "score": ANY(__magic_name__				)}]				)
				self.assertTrue(outputs[0]["label"] in model.config.idalabel.values()				)

				lowerCAmelCase__										=				["HuggingFace is in ", "Paris is in France"]
				lowerCAmelCase__										=				text_classifier(__magic_name__				)
				self.assertEqual(
				    nested_simplify(__magic_name__				)   ,				[{"label": ANY(__magic_name__				), "score": ANY(__magic_name__				)}, {"label": ANY(__magic_name__				), "score": ANY(__magic_name__				)}]   ,				)
				self.assertTrue(outputs[0]["label"] in model.config.idalabel.values()				)
				self.assertTrue(outputs[1]["label"] in model.config.idalabel.values()				)

				# Forcing to get all results with `top_k=None`
				# This is NOT the legacy format
				lowerCAmelCase__										=				text_classifier(__magic_name__   ,				top_k=__magic_name__				)
				lowerCAmelCase__										=				len(model.config.idalabel.values()				)
				self.assertEqual(
				    nested_simplify(__magic_name__				)   ,				[[{"label": ANY(__magic_name__				), "score": ANY(__magic_name__				)}] * N, [{"label": ANY(__magic_name__				), "score": ANY(__magic_name__				)}] * N]   ,				)

				lowerCAmelCase__										=				{"text": "HuggingFace is in ", "text_pair": "Paris is in France"}
				lowerCAmelCase__										=				text_classifier(__magic_name__				)
				self.assertEqual(
				    nested_simplify(__magic_name__				)   ,				{"label": ANY(__magic_name__				), "score": ANY(__magic_name__				)}   ,				)
				self.assertTrue(outputs["label"] in model.config.idalabel.values()				)

				# This might be used a text pair, but tokenizer + pipe interaction
				# makes it hard to understand that it's not using the pair properly
				# https://github.com/huggingface/transformers/issues/17305
				# We disabled this usage instead as it was outputting wrong outputs.
				lowerCAmelCase__										=				[["HuggingFace is in ", "Paris is in France"]]
				with self.assertRaises(__magic_name__				):
							text_classifier(__magic_name__				)

				# This used to be valid for doing text pairs
				# We're keeping it working because of backward compatibility
				lowerCAmelCase__										=				text_classifier([[["HuggingFace is in ", "Paris is in France"]]]				)
				self.assertEqual(
				    nested_simplify(__magic_name__				)   ,				[{"label": ANY(__magic_name__				), "score": ANY(__magic_name__				)}]   ,				)
				self.assertTrue(outputs[0]["label"] in model.config.idalabel.values()				)












import requests

a__      :     Any         =		'YOUR API KEY'

def      UpperCAmelCase_    (    _UpperCAmelCase							:str  ,						_UpperCAmelCase							:str = giphy_api_key				)	->				list:
     '''simple docstring'''


     A_          =       '''+'''.join(query.split()				)
     A_          =       f'https://api.giphy.com/v1/gifs/search?q={formatted_query}&api_key={api_key}'
     A_          =       requests.get(_UpperCAmelCase				).json()['''data''']
     return [gif["url"] for gif in gifs]


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



