2626from numpy .linalg import norm
2727from packaging import version
2828
29+ from .constants import DIFFUSERS_REQUEST_TIMEOUT
2930from .import_utils import (
3031 BACKENDS_MAPPING ,
3132 is_accelerate_available ,
4748from .logging import get_logger
4849
4950
50- # Set global timeout
51- request_timeout = int (os .environ .get ("DIFFUSERS_REQUEST_TIMEOUT" , 60 ))
52-
5351global_rng = random .Random ()
5452
5553logger = get_logger (__name__ )
@@ -597,7 +595,7 @@ def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -
597595 # local_path can be passed to correct images of tests
598596 return Path (local_path , arry .split ("/" )[- 5 ], arry .split ("/" )[- 2 ], arry .split ("/" )[- 1 ]).as_posix ()
599597 elif arry .startswith ("http://" ) or arry .startswith ("https://" ):
600- response = requests .get (arry , timeout = request_timeout )
598+ response = requests .get (arry , timeout = DIFFUSERS_REQUEST_TIMEOUT )
601599 response .raise_for_status ()
602600 arry = np .load (BytesIO (response .content ))
603601 elif os .path .isfile (arry ):
@@ -618,7 +616,7 @@ def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -
618616
619617
620618def load_pt (url : str , map_location : str ):
621- response = requests .get (url , timeout = request_timeout )
619+ response = requests .get (url , timeout = DIFFUSERS_REQUEST_TIMEOUT )
622620 response .raise_for_status ()
623621 arry = torch .load (BytesIO (response .content ), map_location = map_location )
624622 return arry
@@ -637,7 +635,7 @@ def load_image(image: Union[str, PIL.Image.Image]) -> PIL.Image.Image:
637635 """
638636 if isinstance (image , str ):
639637 if image .startswith ("http://" ) or image .startswith ("https://" ):
640- image = PIL .Image .open (requests .get (image , stream = True , timeout = request_timeout ).raw )
638+ image = PIL .Image .open (requests .get (image , stream = True , timeout = DIFFUSERS_REQUEST_TIMEOUT ).raw )
641639 elif os .path .isfile (image ):
642640 image = PIL .Image .open (image )
643641 else :
0 commit comments