
"""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	 =							False


if is_vision_available():
    from PIL import Image
else:


    class A_			:




      '''simple docstring'''







      @staticmethod
      def  UpperCamelCase__      (	*lowercase_       ,     **lowercase_						):

         """simple docstring"""
         pass


@is_pipeline_test
@require_vision
class A_			(unittest.TestCase   ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__    :		int						  =	MODEL_FOR_VISION_2_SEQ_MAPPING
  SCREAMING_SNAKE_CASE__    :		int						  =	TF_MODEL_FOR_VISION_2_SEQ_MAPPING







  def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_						):

     """simple docstring"""
     UpperCAmelCase_      :      List[str]      =					pipeline("image-to-text"       ,     model=lowercase_       ,     tokenizer=lowercase_       ,     image_processor=lowercase_						)
     UpperCAmelCase_      :      str      =					[
         Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						),
         './tests/fixtures/tests_samples/COCO/000000039769.png',
     ]
     return pipe, examples







  def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_						):

     """simple docstring"""
     UpperCAmelCase_      :      str      =					pipe(lowercase_						)
     self.assertEqual(
         lowercase_       ,     [
             [{"generated_text": ANY(lowercase_						)}],
             [{"generated_text": ANY(lowercase_						)}],
         ]       ,     )







  @require_tf
  def  UpperCamelCase__      (	self						):

     """simple docstring"""
     UpperCAmelCase_      :      Tuple      =					pipeline("image-to-text"       ,     model="hf-internal-testing/tiny-random-vit-gpt2"       ,     framework="tf"						)
     UpperCAmelCase_      :      Optional[int]      =					'./tests/fixtures/tests_samples/COCO/000000039769.png'

     UpperCAmelCase_      :      Optional[int]      =					pipe(lowercase_						)
     self.assertEqual(
         lowercase_       ,     [
             {
                 "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
             },
         ]       ,     )

     UpperCAmelCase_      :      List[Any]      =					pipe([image, image]						)
     self.assertEqual(
         lowercase_       ,     [
             [
                 {
                     "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                 }
             ],
             [
                 {
                     "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                 }
             ],
         ]       ,     )

     UpperCAmelCase_      :      str      =					pipe(lowercase_       ,     max_new_tokens=1						)
     self.assertEqual(
         lowercase_       ,     [{"generated_text": "growth"}]       ,     )







  @require_torch
  def  UpperCamelCase__      (	self						):

     """simple docstring"""
     UpperCAmelCase_      :      Union[str, Any]      =					pipeline("image-to-text"       ,     model="hf-internal-testing/tiny-random-vit-gpt2"						)
     UpperCAmelCase_      :      Any      =					'./tests/fixtures/tests_samples/COCO/000000039769.png'

     UpperCAmelCase_      :      int      =					pipe(lowercase_						)
     self.assertEqual(
         lowercase_       ,     [
             {
                 "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
             },
         ]       ,     )

     UpperCAmelCase_      :      Tuple      =					pipe([image, image]						)
     self.assertEqual(
         lowercase_       ,     [
             [
                 {
                     "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                 }
             ],
             [
                 {
                     "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                 }
             ],
         ]       ,     )







  @require_torch
  def  UpperCamelCase__      (	self						):

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

     UpperCAmelCase_      :      Dict      =					pipe(lowercase_       ,     prompt=lowercase_						)
     self.assertTrue(outputs[0]["generated_text"].startswith(lowercase_						)						)







  @slow
  @require_torch
  def  UpperCamelCase__      (	self						):

     """simple docstring"""
     UpperCAmelCase_      :      List[str]      =					pipeline("image-to-text"       ,     model="ydshieh/vit-gpt2-coco-en"						)
     UpperCAmelCase_      :      Any      =					'./tests/fixtures/tests_samples/COCO/000000039769.png'

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

     UpperCAmelCase_      :      Union[str, Any]      =					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						):

     """simple docstring"""
     UpperCAmelCase_      :      int      =					pipeline("image-to-text"       ,     model="Salesforce/blip-image-captioning-base"						)
     UpperCAmelCase_      :      Tuple      =					'https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'
     UpperCAmelCase_      :      List[Any]      =					Image.open(requests.get(lowercase_       ,     stream=lowercase_						).raw						)

     UpperCAmelCase_      :      Optional[Any]      =					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						):

     """simple docstring"""
     UpperCAmelCase_      :      Optional[Any]      =					pipeline("image-to-text"       ,     model="microsoft/git-base-coco"						)
     UpperCAmelCase_      :      str      =					'https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'
     UpperCAmelCase_      :      Dict      =					Image.open(requests.get(lowercase_       ,     stream=lowercase_						).raw						)

     UpperCAmelCase_      :      Optional[int]      =					pipe(lowercase_						)
     self.assertEqual(lowercase_       ,     [{"generated_text": "a cartoon of a purple character."}]						)







  @slow
  @require_torch
  def  UpperCamelCase__      (	self						):

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

     UpperCAmelCase_      :      int      =					'a photography of'

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

     with self.assertRaises(lowercase_						):
        UpperCAmelCase_      :      Union[str, Any]      =					pipe([image, image]       ,     prompt=[prompt, prompt]						)







  @slow
  @require_torch
  def  UpperCamelCase__      (	self						):

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

     UpperCAmelCase_      :      Optional[int]      =					'a photo of a'

     UpperCAmelCase_      :      Optional[int]      =					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_						):
        UpperCAmelCase_      :      List[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						):

     """simple docstring"""
     UpperCAmelCase_      :      Union[str, Any]      =					pipeline("image-to-text"       ,     model="google/pix2struct-ai2d-base"						)
     UpperCAmelCase_      :      List[str]      =					'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'
     UpperCAmelCase_      :      Tuple      =					Image.open(requests.get(lowercase_       ,     stream=lowercase_						).raw						)

     UpperCAmelCase_      :      str      =					'What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud'

     UpperCAmelCase_      :      Union[str, Any]      =					pipe(lowercase_       ,     prompt=lowercase_						)
     self.assertEqual(lowercase_       ,     [{"generated_text": "ash cloud"}]						)

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







  @slow
  @require_tf
  def  UpperCamelCase__      (	self						):

     """simple docstring"""
     UpperCAmelCase_      :      List[str]      =					pipeline("image-to-text"       ,     model="ydshieh/vit-gpt2-coco-en"       ,     framework="tf"						)
     UpperCAmelCase_      :      Dict      =					'./tests/fixtures/tests_samples/COCO/000000039769.png'

     UpperCAmelCase_      :      Optional[Any]      =					pipe(lowercase_						)
     self.assertEqual(lowercase_       ,     [{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}]						)

     UpperCAmelCase_      :      List[Any]      =					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 statistics import mean







def 			__a  (	__lowerCamelCase						):
   UpperCAmelCase_      :      Dict      =					2
   UpperCAmelCase_      :      Any      =					list(__lowerCamelCase						)
   UpperCAmelCase_      :      List[Any]      =					[0] * len(__lowerCamelCase						)
   UpperCAmelCase_      :      str      =					0
   while True:
      UpperCAmelCase_      :      int      =					True
      for i, burst_time in enumerate(__lowerCamelCase						):
         if rem_burst_times[i] > 0:
            UpperCAmelCase_      :      List[Any]      =					False
            if rem_burst_times[i] > quantum:
               t += quantum
               rem_burst_times[i] -= quantum
            else:
               t += rem_burst_times[i]
               UpperCAmelCase_      :      Optional[int]      =					t - burst_time
               UpperCAmelCase_      :      Union[str, Any]      =					0
      if done is True:
         return waiting_times







def 			__a  (	__lowerCamelCase,	__lowerCamelCase						):
   return [burst + waiting for burst, waiting in zip(__lowerCamelCase,	__lowerCamelCase						)]


if __name__ == "__main__":
    _a	 =							[3, 5, 7]
    _a	 =							calculate_waiting_times(burst_times)
    _a	 =							calculate_turn_around_times(burst_times, waiting_times)
    print('Process ID \tBurst Time \tWaiting Time \tTurnaround Time')
    for i, burst_time in enumerate(burst_times):
        print(
            f"""  {i + 1}\t\t  {burst_time}\t\t  {waiting_times[i]}\t\t  """
            f"""{turn_around_times[i]}"""
        )
    print(f"""\nAverage waiting time = {mean(waiting_times):.5f}""")
    print(f"""Average turn around time = {mean(turn_around_times):.5f}""")


