


'''simple docstring'''






# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ..models.auto import AutoModelForVisionaSeq
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
 from PIL import Image




class 	a       (       _SCREAMING_SNAKE_CASE    ):
 _lowerCAmelCase	   =		"""Salesforce/blip-image-captioning-base"""
 _lowerCAmelCase	   =		(
     """This is a tool that generates a description of an image. It takes an input named `image` which should be the """
     """image to caption, and returns a text that contains the description in English."""
 )
 _lowerCAmelCase	   =		"""image_captioner"""
 _lowerCAmelCase	   =		AutoModelForVisionaSeq

 _lowerCAmelCase	   =		["""image"""]
 _lowerCAmelCase	   =		["""text"""]
 def __init__(	self ,			*__magic_name__ ,			**__magic_name__  )   ->							Optional[Any]:
      requires_backends(self ,			['vision']  )
      super().__init__(*__magic_name__ ,			**__magic_name__  )
 def 							__UpperCAmelCase						(	self ,			__magic_name__  )   ->							List[str]:
      return self.pre_processor(images=__magic_name__ ,			return_tensors='pt'  )
 def 							__UpperCAmelCase						(	self ,			__magic_name__  )   ->							Optional[Any]:
      return self.model.generate(**__magic_name__  )




 def 							__UpperCAmelCase						(	self ,			__magic_name__  )   ->							Optional[int]:
      return self.pre_processor.batch_decode(__magic_name__ ,			skip_special_tokens=__magic_name__  )[0].strip()





'''simple docstring'''






import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline






@pytest.mark.integration
def 		_A			()				->					Optional[Any]:




     '''simple docstring'''



     with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT						):
          with pytest.raises(lowerCAmelCase__						):
               requests.request('GET'			,  'https://huggingface.co'						)
          with pytest.raises(requests.exceptions.ConnectTimeout						):
               requests.request('GET'			,  'https://huggingface.co'			,  timeout=1.0						)






@pytest.mark.integration
def 		_A			()				->					Any:




     '''simple docstring'''



     with offline(OfflineSimulationMode.CONNECTION_FAILS						):
          with pytest.raises(requests.exceptions.ConnectionError						):
               requests.request('GET'			,  'https://huggingface.co'						)






def 		_A			()				->					Dict:




     '''simple docstring'''



     with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1						):
          with pytest.raises(lowerCAmelCase__						):
               http_head('https://huggingface.co'						)

