


'''simple docstring'''
import unittest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TextaTextGenerationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch
from transformers.utils import is_torch_available

from .test_pipelines_common import ANY


if is_torch_available():
  import torch
@is_pipeline_test
class        lowercase     (							unittest.TestCase ):

  """simple docstring"""

  _a   			=    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
  _a   			=    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING




  def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_   ,       UpperCamelCase_							):

       '''simple docstring'''


       UpperCamelCase__       :str							 =			TextaTextGenerationPipeline(model=__a   ,       tokenizer=__a							)
       return generator, ["Something to write", "Something else"]




  def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_							):

       '''simple docstring'''


       UpperCamelCase__       :int							 =			generator('''Something there'''							)
       self.assertEqual(__a   ,       [{'''generated_text''': ANY(__a							)}]							)
       # These are encoder decoder, they don't just append to incoming string
       self.assertFalse(outputs[0]['''generated_text'''].startswith('''Something there'''							)							)

       UpperCamelCase__       :str							 =			generator(['''This is great !''', '''Something else''']   ,       num_return_sequences=2   ,       do_sample=__a							)
       self.assertEqual(
           __a   ,       [
               [{'''generated_text''': ANY(__a							)}, {'''generated_text''': ANY(__a							)}],
               [{'''generated_text''': ANY(__a							)}, {'''generated_text''': ANY(__a							)}],
           ]   ,       )

       UpperCamelCase__       :int							 =			generator(
           ['''This is great !''', '''Something else''']   ,       num_return_sequences=2   ,       batch_size=2   ,       do_sample=__a							)
       self.assertEqual(
           __a   ,       [
               [{'''generated_text''': ANY(__a							)}, {'''generated_text''': ANY(__a							)}],
               [{'''generated_text''': ANY(__a							)}, {'''generated_text''': ANY(__a							)}],
           ]   ,       )

       with self.assertRaises(__a							):
            generator(4							)




  @require_torch
  def    lowerCAmelCase__    (		self							):

       '''simple docstring'''


       UpperCamelCase__       :int							 =			pipeline('''text2text-generation'''   ,       model='''patrickvonplaten/t5-tiny-random'''   ,       framework='''pt'''							)
       # do_sample=False necessary for reproducibility
       UpperCamelCase__       :Tuple							 =			generator('''Something there'''   ,       do_sample=__a							)
       self.assertEqual(__a   ,       [{'''generated_text''': ''''''}]							)

       UpperCamelCase__       :List[str]							 =			3
       UpperCamelCase__       :List[str]							 =			generator(
           '''Something there'''   ,       num_return_sequences=__a   ,       num_beams=__a   ,       )
       UpperCamelCase__       :Any							 =			[
           {'''generated_text''': '''Beide Beide Beide Beide Beide Beide Beide Beide Beide'''},
           {'''generated_text''': '''Beide Beide Beide Beide Beide Beide Beide Beide'''},
           {'''generated_text''': ''''''},
       ]
       self.assertEqual(__a   ,       __a							)

       UpperCamelCase__       :List[Any]							 =			generator('''This is a test'''   ,       do_sample=__a   ,       num_return_sequences=2   ,       return_tensors=__a							)
       self.assertEqual(
           __a   ,       [
               {'''generated_token_ids''': ANY(torch.Tensor							)},
               {'''generated_token_ids''': ANY(torch.Tensor							)},
           ]   ,       )
       UpperCamelCase__       :Dict							 =			generator.model.config.eos_token_id
       UpperCamelCase__       :Union[str, Any]							 =			'''<pad>'''
       UpperCamelCase__       :List[str]							 =			generator(
           ['''This is a test''', '''This is a second test''']   ,       do_sample=__a   ,       num_return_sequences=2   ,       batch_size=2   ,       return_tensors=__a   ,       )
       self.assertEqual(
           __a   ,       [
               [
                   {'''generated_token_ids''': ANY(torch.Tensor							)},
                   {'''generated_token_ids''': ANY(torch.Tensor							)},
               ],
               [
                   {'''generated_token_ids''': ANY(torch.Tensor							)},
                   {'''generated_token_ids''': ANY(torch.Tensor							)},
               ],
           ]   ,       )




  @require_tf
  def    lowerCAmelCase__    (		self							):

       '''simple docstring'''


       UpperCamelCase__       :Dict							 =			pipeline('''text2text-generation'''   ,       model='''patrickvonplaten/t5-tiny-random'''   ,       framework='''tf'''							)
       # do_sample=False necessary for reproducibility
       UpperCamelCase__       :Dict							 =			generator('''Something there'''   ,       do_sample=__a							)
       self.assertEqual(__a   ,       [{'''generated_text''': ''''''}]							)



'''simple docstring'''
import socket


def       a				(      )  ->     Dict:



					'''simple docstring'''






					UpperCamelCase__       :int							 =			socket.socket(socket.AF_INET			, socket.SOCK_STREAM       )
					UpperCamelCase__       :List[Any]							 =			socket.gethostname()
					UpperCamelCase__       :List[str]							 =			12312

					sock.connect((host, port)       )
					sock.send(B'''Hello server!'''       )

					with open('''Received_file'''			, '''wb'''       ) as out_file:
										print('''File opened'''       )
										print('''Receiving data...'''       )
										while True:
															UpperCamelCase__       :str							 =			sock.recv(1024       )
															if not data:
																				break
															out_file.write(__a       )

					print('''Successfully received the file'''       )
					sock.close()
					print('''Connection closed'''       )


if __name__ == "__main__":
		main()