





'''simple docstring'''






from PIL import Image



def        UpperCamelCase__		(						__magic_name__  :   Image      )				->			Image:
 '''simple docstring'''






 snake_case__  ,							snake_case__     :					Tuple    =  image.size
 snake_case__     :					List[Any]    =  0
 snake_case__     :					Optional[Any]    =  image.load()
 for i in range(__magic_name__      ):
  for j in range(__magic_name__      ):
   snake_case__     :					Any    =  pixels[j, i]
   mean += pixel
 mean //= width * height

 for j in range(__magic_name__      ):
  for i in range(__magic_name__      ):
   snake_case__     :					Any    =  2_55 if pixels[i, j] > mean else 0
 return image


if __name__ == "__main__":
    A_		:  Any		 =						mean_threshold(Image.open("path_to_image").convert("L"))
    image.save("output_image_path")












import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline

@pytest.mark.integration
def   __lowercase       (			):







				"""simple docstring"""






				with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT			):
								with pytest.raises(snake_case			):
												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   __lowercase       (			):







				"""simple docstring"""






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

def   __lowercase       (			):







				"""simple docstring"""






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






