






'''simple docstring'''







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:
       __A      :       List[str]      =	False


if is_vision_available():
       from PIL import Image
else:






       class 					a__    :
            '''simple docstring'''







            @staticmethod
            def     _UpperCamelCase   (*lowercase__    :	Optional[int]				,				**lowercase__    :	Optional[Any]					)  ->       Tuple:
                  pass






@is_pipeline_test
@require_vision
class 					a__    (			unittest.TestCase						):
     '''simple docstring'''







     _snake_case             =  MODEL_FOR_VISION_2_SEQ_MAPPING
     _snake_case             =  TF_MODEL_FOR_VISION_2_SEQ_MAPPING






     def     _UpperCamelCase   (self    :	List[str]				,				lowercase__    :	List[Any]				,				lowercase__    :	Dict				,				lowercase__    :	Union[str, Any]					)  ->       Optional[Any]:
           __A		   =      pipeline("image-to-text"				,				model=lowercase__				,				tokenizer=lowercase__				,				image_processor=lowercase__					)
           __A		   =      [
               Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"					),
               "./tests/fixtures/tests_samples/COCO/000000039769.png",
           ]
           return pipe, examples






     def     _UpperCamelCase   (self    :	List[str]				,				lowercase__    :	int				,				lowercase__    :	List[Any]					)  ->       Union[str, Any]:
           __A		   =      pipe(lowercase__					)
           self.assertEqual(
               lowercase__				,				[
                   [{"generated_text": ANY(lowercase__					)}],
                   [{"generated_text": ANY(lowercase__					)}],
               ]				,				)






     @require_tf
     def     _UpperCamelCase   (self    :	int					)  ->       Tuple:
           __A		   =      pipeline("image-to-text"				,				model="hf-internal-testing/tiny-random-vit-gpt2"				,				framework="tf"					)
           __A		   =      "./tests/fixtures/tests_samples/COCO/000000039769.png"

           __A		   =      pipe(lowercase__					)
           self.assertEqual(
               lowercase__				,				[
                   {
                       "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                   },
               ]				,				)

           __A		   =      pipe([image, image]					)
           self.assertEqual(
               lowercase__				,				[
                   [
                       {
                           "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                       }
                   ],
                   [
                       {
                           "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                       }
                   ],
               ]				,				)

           __A		   =      pipe(lowercase__				,				max_new_tokens=1					)
           self.assertEqual(
               lowercase__				,				[{"generated_text": "growth"}]				,				)






     @require_torch
     def     _UpperCamelCase   (self    :	int					)  ->       Union[str, Any]:
           __A		   =      pipeline("image-to-text"				,				model="hf-internal-testing/tiny-random-vit-gpt2"					)
           __A		   =      "./tests/fixtures/tests_samples/COCO/000000039769.png"

           __A		   =      pipe(lowercase__					)
           self.assertEqual(
               lowercase__				,				[
                   {
                       "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                   },
               ]				,				)

           __A		   =      pipe([image, image]					)
           self.assertEqual(
               lowercase__				,				[
                   [
                       {
                           "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                       }
                   ],
                   [
                       {
                           "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                       }
                   ],
               ]				,				)






     @require_torch
     def     _UpperCamelCase   (self    :	Any					)  ->       List[str]:
           __A		   =      pipeline("image-to-text"				,				model="hf-internal-testing/tiny-random-BlipForConditionalGeneration"					)
           __A		   =      "./tests/fixtures/tests_samples/COCO/000000039769.png"
           __A		   =      "a photo of"

           __A		   =      pipe(lowercase__				,				prompt=lowercase__					)
           self.assertTrue(outputs[0]["generated_text"].startswith(lowercase__					)					)






     @slow
     @require_torch
     def     _UpperCamelCase   (self    :	List[str]					)  ->       Optional[Any]:
           __A		   =      pipeline("image-to-text"				,				model="ydshieh/vit-gpt2-coco-en"					)
           __A		   =      "./tests/fixtures/tests_samples/COCO/000000039769.png"

           __A		   =      pipe(lowercase__					)
           self.assertEqual(lowercase__				,				[{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}]					)

           __A		   =      pipe([image, image]					)
           self.assertEqual(
               lowercase__				,				[
                   [{"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    :	int					)  ->       List[Any]:
           __A		   =      pipeline("image-to-text"				,				model="Salesforce/blip-image-captioning-base"					)
           __A		   =      "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
           __A		   =      Image.open(requests.get(lowercase__				,				stream=lowercase__					).raw					)

           __A		   =      pipe(lowercase__					)
           self.assertEqual(lowercase__				,				[{"generated_text": "a pink pokemon pokemon with a blue shirt and a blue shirt"}]					)






     @slow
     @require_torch
     def     _UpperCamelCase   (self    :	Optional[Any]					)  ->       Any:
           __A		   =      pipeline("image-to-text"				,				model="microsoft/git-base-coco"					)
           __A		   =      "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
           __A		   =      Image.open(requests.get(lowercase__				,				stream=lowercase__					).raw					)

           __A		   =      pipe(lowercase__					)
           self.assertEqual(lowercase__				,				[{"generated_text": "a cartoon of a purple character."}]					)






     @slow
     @require_torch
     def     _UpperCamelCase   (self    :	Union[str, Any]					)  ->       Optional[Any]:
           __A		   =      pipeline("image-to-text"				,				model="Salesforce/blip-image-captioning-base"					)
           __A		   =      "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
           __A		   =      Image.open(requests.get(lowercase__				,				stream=lowercase__					).raw					)

           __A		   =      "a photography of"

           __A		   =      pipe(lowercase__				,				prompt=lowercase__					)
           self.assertEqual(lowercase__				,				[{"generated_text": "a photography of a volcano"}]					)

           with self.assertRaises(lowercase__					):
                 __A		   =      pipe([image, image]				,				prompt=[prompt, prompt]					)






     @slow
     @require_torch
     def     _UpperCamelCase   (self    :	Union[str, Any]					)  ->       Optional[Any]:
           __A		   =      pipeline("image-to-text"				,				model="microsoft/git-base-coco"					)
           __A		   =      "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
           __A		   =      Image.open(requests.get(lowercase__				,				stream=lowercase__					).raw					)

           __A		   =      "a photo of a"

           __A		   =      pipe(lowercase__				,				prompt=lowercase__					)
           self.assertEqual(lowercase__				,				[{"generated_text": "a photo of a tent with a tent and a tent in the background."}]					)

           with self.assertRaises(lowercase__					):
                 __A		   =      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[Any]					)  ->       List[Any]:
           __A		   =      pipeline("image-to-text"				,				model="google/pix2struct-ai2d-base"					)
           __A		   =      "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
           __A		   =      Image.open(requests.get(lowercase__				,				stream=lowercase__					).raw					)

           __A		   =      "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"

           __A		   =      pipe(lowercase__				,				prompt=lowercase__					)
           self.assertEqual(lowercase__				,				[{"generated_text": "ash cloud"}]					)

           with self.assertRaises(lowercase__					):
                 __A		   =      pipe([image, image]				,				prompt=[prompt, prompt]					)






     @slow
     @require_tf
     def     _UpperCamelCase   (self    :	List[str]					)  ->       Any:
           __A		   =      pipeline("image-to-text"				,				model="ydshieh/vit-gpt2-coco-en"				,				framework="tf"					)
           __A		   =      "./tests/fixtures/tests_samples/COCO/000000039769.png"

           __A		   =      pipe(lowercase__					)
           self.assertEqual(lowercase__				,				[{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}]					)

           __A		   =      pipe([image, image]					)
           self.assertEqual(
               lowercase__				,				[
                   [{"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 "}],
               ]				,				)










'''simple docstring'''







from __future__ import annotations

from queue import Queue






class 					a__    :
     '''simple docstring'''







     def __init__(self    :	Any					)  ->       None:
           __A		   =      {}






     def     _UpperCamelCase   (self    :	Optional[int]					)  ->       None:
           for i in self.vertices:
                 print(lowercase__				,				" : "				,				" -> ".join([str(lowercase__					) for j in self.vertices[i]]					)					)






     def     _UpperCamelCase   (self    :	Union[str, Any]				,				lowercase__    :	int				,				lowercase__    :	int					)  ->       None:
           if from_vertex in self.vertices:
                 self.vertices[from_vertex].append(lowercase__					)
           else:
                 __A		   =      [to_vertex]






     def     _UpperCamelCase   (self    :	Optional[int]				,				lowercase__    :	int					)  ->       set[int]:
           __A		   =      set()

           # create a first in first out queue to store all the vertices for BFS
           __A		   =      Queue()

           # mark the source node as visited and enqueue it
           visited.add(lowercase__					)
           queue.put(lowercase__					)

           while not queue.empty():
                 __A		   =      queue.get()

                 # loop through all adjacent vertex and enqueue it if not yet visited
                 for adjacent_vertex in self.vertices[vertex]:
                       if adjacent_vertex not in visited:
                             queue.put(lowercase__					)
                             visited.add(lowercase__					)
           return visited


if __name__ == "__main__":
       from doctest import testmod

       testmod(verbose=True)

       __A      :       Dict      =	Graph()
       g.add_edge(0, 1)
       g.add_edge(0, 2)
       g.add_edge(1, 2)
       g.add_edge(2, 0)
       g.add_edge(2, 3)
       g.add_edge(3, 3)

       g.print_graph()
       # 0  :  1 -> 2
       # 1  :  2
       # 2  :  0 -> 3
       # 3  :  3

       assert sorted(g.bfs(2)) == [0, 1, 2, 3]


