import unittest

import requests

from transformers import MODEL_FOR_VISION_2_SEQ_MAPPING, TF_MODEL_FOR_VISION_2_SEQ_MAPPING, is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    is_torch_available,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_torch_available():
     from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
     __snake_case			      =    False


if is_vision_available():
     from PIL import Image
else:







     class 			__snake_case   :
      @staticmethod
      def 	UpperCAmelCase__       (  *snake_case__		,   **snake_case__						)	->							Tuple:
            '''simple docstring'''





            pass







@is_pipeline_test
@require_vision
class 			__snake_case   (     unittest.TestCase   ):
 __lowerCamelCase    :   Dict     =      MODEL_FOR_VISION_2_SEQ_MAPPING
 __lowerCamelCase    :   Any     =      TF_MODEL_FOR_VISION_2_SEQ_MAPPING
 def 	UpperCAmelCase__       (  self		,   snake_case__		,   snake_case__		,   snake_case__						)	->							str:
       '''simple docstring'''





       UpperCAmelCase    : Dict      =pipeline('''image-to-text'''		,   model=snake_case__		,   tokenizer=snake_case__		,   image_processor=snake_case__						)
       UpperCAmelCase    : List[str]      =[
           Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''						),
           '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
       ]
       return pipe, examples
 def 	UpperCAmelCase__       (  self		,   snake_case__		,   snake_case__						)	->							str:
       '''simple docstring'''





       UpperCAmelCase    : Optional[Any]      =pipe(snake_case__						)
       self.assertEqual(
           snake_case__		,   [
               [{'''generated_text''': ANY(snake_case__						)}],
               [{'''generated_text''': ANY(snake_case__						)}],
           ]		,   )
 @require_tf
 def 	UpperCAmelCase__       (  self						)	->							List[Any]:
       '''simple docstring'''





       UpperCAmelCase    : List[Any]      =pipeline('''image-to-text'''		,   model='''hf-internal-testing/tiny-random-vit-gpt2'''		,   framework='''tf'''						)
       UpperCAmelCase    : Any      ='''./tests/fixtures/tests_samples/COCO/000000039769.png'''

       UpperCAmelCase    : str      =pipe(snake_case__						)
       self.assertEqual(
           snake_case__		,   [
               {
                   '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
               },
           ]		,   )

       UpperCAmelCase    : str      =pipe([image, image]						)
       self.assertEqual(
           snake_case__		,   [
               [
                   {
                       '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                   }
               ],
               [
                   {
                       '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                   }
               ],
           ]		,   )

       UpperCAmelCase    : Dict      =pipe(snake_case__		,   max_new_tokens=1						)
       self.assertEqual(
           snake_case__		,   [{'''generated_text''': '''growth'''}]		,   )
 @require_torch
 def 	UpperCAmelCase__       (  self						)	->							Optional[int]:
       '''simple docstring'''





       UpperCAmelCase    : Tuple      =pipeline('''image-to-text'''		,   model='''hf-internal-testing/tiny-random-vit-gpt2'''						)
       UpperCAmelCase    : List[Any]      ='''./tests/fixtures/tests_samples/COCO/000000039769.png'''

       UpperCAmelCase    : str      =pipe(snake_case__						)
       self.assertEqual(
           snake_case__		,   [
               {
                   '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
               },
           ]		,   )

       UpperCAmelCase    : Dict      =pipe([image, image]						)
       self.assertEqual(
           snake_case__		,   [
               [
                   {
                       '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                   }
               ],
               [
                   {
                       '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                   }
               ],
           ]		,   )
 @require_torch
 def 	UpperCAmelCase__       (  self						)	->							Tuple:
       '''simple docstring'''





       UpperCAmelCase    : Union[str, Any]      =pipeline('''image-to-text'''		,   model='''hf-internal-testing/tiny-random-BlipForConditionalGeneration'''						)
       UpperCAmelCase    : List[str]      ='''./tests/fixtures/tests_samples/COCO/000000039769.png'''
       UpperCAmelCase    : List[Any]      ='''a photo of'''

       UpperCAmelCase    : Union[str, Any]      =pipe(snake_case__		,   prompt=snake_case__						)
       self.assertTrue(outputs[0]['''generated_text'''].startswith(snake_case__						)						)
 @slow
 @require_torch
 def 	UpperCAmelCase__       (  self						)	->							Optional[int]:
       '''simple docstring'''





       UpperCAmelCase    : Union[str, Any]      =pipeline('''image-to-text'''		,   model='''ydshieh/vit-gpt2-coco-en'''						)
       UpperCAmelCase    : Optional[Any]      ='''./tests/fixtures/tests_samples/COCO/000000039769.png'''

       UpperCAmelCase    : Tuple      =pipe(snake_case__						)
       self.assertEqual(snake_case__		,   [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}]						)

       UpperCAmelCase    : List[Any]      =pipe([image, image]						)
       self.assertEqual(
           snake_case__		,   [
               [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
               [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
           ]		,   )
 @slow
 @require_torch
 def 	UpperCAmelCase__       (  self						)	->							Optional[Any]:
       '''simple docstring'''





       UpperCAmelCase    : Optional[int]      =pipeline('''image-to-text'''		,   model='''Salesforce/blip-image-captioning-base'''						)
       UpperCAmelCase    : Union[str, Any]      ='''https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'''
       UpperCAmelCase    : Union[str, Any]      =Image.open(requests.get(snake_case__		,   stream=snake_case__						).raw						)

       UpperCAmelCase    : Optional[int]      =pipe(snake_case__						)
       self.assertEqual(snake_case__		,   [{'''generated_text''': '''a pink pokemon pokemon with a blue shirt and a blue shirt'''}]						)
 @slow
 @require_torch
 def 	UpperCAmelCase__       (  self						)	->							Union[str, Any]:
       '''simple docstring'''





       UpperCAmelCase    : int      =pipeline('''image-to-text'''		,   model='''microsoft/git-base-coco'''						)
       UpperCAmelCase    : int      ='''https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'''
       UpperCAmelCase    : Union[str, Any]      =Image.open(requests.get(snake_case__		,   stream=snake_case__						).raw						)

       UpperCAmelCase    : Optional[int]      =pipe(snake_case__						)
       self.assertEqual(snake_case__		,   [{'''generated_text''': '''a cartoon of a purple character.'''}]						)
 @slow
 @require_torch
 def 	UpperCAmelCase__       (  self						)	->							int:
       '''simple docstring'''





       UpperCAmelCase    : Optional[Any]      =pipeline('''image-to-text'''		,   model='''Salesforce/blip-image-captioning-base'''						)
       UpperCAmelCase    : List[str]      ='''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
       UpperCAmelCase    : Dict      =Image.open(requests.get(snake_case__		,   stream=snake_case__						).raw						)

       UpperCAmelCase    : Any      ='''a photography of'''

       UpperCAmelCase    : Dict      =pipe(snake_case__		,   prompt=snake_case__						)
       self.assertEqual(snake_case__		,   [{'''generated_text''': '''a photography of a volcano'''}]						)

       with self.assertRaises(snake_case__						):
             UpperCAmelCase    : List[Any]      =pipe([image, image]		,   prompt=[prompt, prompt]						)
 @slow
 @require_torch
 def 	UpperCAmelCase__       (  self						)	->							List[str]:
       '''simple docstring'''





       UpperCAmelCase    : Optional[int]      =pipeline('''image-to-text'''		,   model='''microsoft/git-base-coco'''						)
       UpperCAmelCase    : str      ='''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
       UpperCAmelCase    : Any      =Image.open(requests.get(snake_case__		,   stream=snake_case__						).raw						)

       UpperCAmelCase    : List[str]      ='''a photo of a'''

       UpperCAmelCase    : List[Any]      =pipe(snake_case__		,   prompt=snake_case__						)
       self.assertEqual(snake_case__		,   [{'''generated_text''': '''a photo of a tent with a tent and a tent in the background.'''}]						)

       with self.assertRaises(snake_case__						):
             UpperCAmelCase    : Union[str, Any]      =pipe([image, image]		,   prompt=[prompt, prompt]						)
 @unittest.skipIf(
     not is_torch_greater_or_equal_than_1_11		,   reason='''`Pix2StructImageProcessor` requires `torch>=1.11.0`.'''						)
 @slow
 @require_torch
 def 	UpperCAmelCase__       (  self						)	->							Optional[int]:
       '''simple docstring'''





       UpperCAmelCase    : List[Any]      =pipeline('''image-to-text'''		,   model='''google/pix2struct-ai2d-base'''						)
       UpperCAmelCase    : int      ='''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
       UpperCAmelCase    : int      =Image.open(requests.get(snake_case__		,   stream=snake_case__						).raw						)

       UpperCAmelCase    : Union[str, Any]      ='''What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud'''

       UpperCAmelCase    : Optional[int]      =pipe(snake_case__		,   prompt=snake_case__						)
       self.assertEqual(snake_case__		,   [{'''generated_text''': '''ash cloud'''}]						)

       with self.assertRaises(snake_case__						):
             UpperCAmelCase    : Optional[Any]      =pipe([image, image]		,   prompt=[prompt, prompt]						)






 @slow
 @require_tf
 def 	UpperCAmelCase__       (  self						)	->							Any:
       '''simple docstring'''





       UpperCAmelCase    : str      =pipeline('''image-to-text'''		,   model='''ydshieh/vit-gpt2-coco-en'''		,   framework='''tf'''						)
       UpperCAmelCase    : int      ='''./tests/fixtures/tests_samples/COCO/000000039769.png'''

       UpperCAmelCase    : Dict      =pipe(snake_case__						)
       self.assertEqual(snake_case__		,   [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}]						)

       UpperCAmelCase    : Any      =pipe([image, image]						)
       self.assertEqual(
           snake_case__		,   [
               [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
               [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
           ]		,   )

def   lowerCAmelCase_ (				__lowerCAmelCase		,					__lowerCAmelCase						)->  list[tuple[int, int, int]]:






      '''simple docstring'''





      UpperCAmelCase    : List[Any]      =sorted(__lowerCAmelCase		,					key=lambda __lowerCAmelCase						: edge[2]						)

      UpperCAmelCase    : Union[str, Any]      =list(range(__lowerCAmelCase						)						)

      def find_parent(__lowerCAmelCase						):
            if i != parent[i]:
                  UpperCAmelCase    : Optional[int]      =find_parent(parent[i]						)
            return parent[i]

      UpperCAmelCase    : Optional[Any]      =0
      UpperCAmelCase    : List[str]      =[]

      for edge in edges:
            UpperCAmelCase    : Dict      =find_parent(edge[0]						)
            UpperCAmelCase    : Optional[Any]      =find_parent(edge[1]						)
            if parent_a != parent_b:
                  minimum_spanning_tree_cost += edge[2]
                  minimum_spanning_tree.append(__lowerCAmelCase						)
                  UpperCAmelCase    : Optional[Any]      =parent_b

      return minimum_spanning_tree


if __name__ == "__main__":  # pragma: no cover
     __snake_case      ,  __snake_case			      =    list(map(int, input().strip().split()))
     __snake_case			      =    []

     for _ in range(num_edges):
          __snake_case      ,  __snake_case      ,  __snake_case			      =    (int(x) for x in input().strip().split())
          edges.append((nodea, nodea, cost))

     kruskal(num_nodes, edges)
