





import importlib
import inspect
import json
import os
import re
import shutil
import sys
from pathlib import Path
from typing import Dict, Optional, Union
from urllib import request

from huggingface_hub import HfFolder, cached_download, hf_hub_download, model_info
from packaging import version

from .. import __version__
from . import DIFFUSERS_DYNAMIC_MODULE_NAME, HF_MODULES_CACHE, logging


A_												=     (
    "https://raw.githubusercontent.com/huggingface/diffusers/{revision}/examples/community/{pipeline}.py"
)


A_												=     logging.get_logger(__name__)  # pylint: disable=invalid-name





def    __UpperCamelCase      (    ) ->str:
					lowerCamelCase__       =       "https://pypi.org/pypi/diffusers/json"
					lowerCamelCase__       =       json.loads(request.urlopen(a).read())["releases"].keys()
					return sorted(a,     key=lambda a: version.Version(a))





def    __UpperCamelCase      (    ) ->List[Any]:
					# This function has already been executed if HF_MODULES_CACHE already is in the Python path.
					if HF_MODULES_CACHE in sys.path:
										return

					sys.path.append(a)
					os.makedirs(a,     exist_ok=a)
					lowerCamelCase__       =       Path(a) / "__init__.py"
					if not init_path.exists():
										init_path.touch()





def    __UpperCamelCase      (    a) ->Tuple:
					init_hf_modules()
					lowerCamelCase__       =       Path(a) / name
					# If the parent module does not exist yet, recursively create it.
					if not dynamic_module_path.parent.exists():
										create_dynamic_module(dynamic_module_path.parent)
					os.makedirs(a,     exist_ok=a)
					lowerCamelCase__       =       dynamic_module_path / "__init__.py"
					if not init_path.exists():
										init_path.touch()





def    __UpperCamelCase      (    a) ->List[str]:
					with open(a,     "r",     encoding="utf-8") as f:
										lowerCamelCase__       =       f.read()

					# Imports of the form `import .xxx`
					lowerCamelCase__       =       re.findall("^\s*import\s+\.(\S+)\s*$",     a,     flags=re.MULTILINE)
					# Imports of the form `from .xxx import yyy`
					relative_imports += re.findall("^\s*from\s+\.(\S+)\s+import",     a,     flags=re.MULTILINE)
					# Unique-ify
					return list(set(a))





def    __UpperCamelCase      (    a) ->Any:
					lowerCamelCase__       =       False
					lowerCamelCase__       =       [module_file]
					lowerCamelCase__       =       []

					# Let's recurse through all relative imports
					while not no_change:
										lowerCamelCase__       =       []
										for f in files_to_check:
															new_imports.extend(get_relative_imports(a))

										lowerCamelCase__       =       Path(a).parent
										lowerCamelCase__       =       [str(module_path / m) for m in new_imports]
										lowerCamelCase__       =       [f for f in new_import_files if f not in all_relative_imports]
										lowerCamelCase__       =       [f"{f}.py" for f in new_import_files]

										lowerCamelCase__       =       len(a) == 0
										all_relative_imports.extend(a)

					return all_relative_imports





def    __UpperCamelCase      (    a) ->Optional[Any]:
					with open(a,     "r",     encoding="utf-8") as f:
										lowerCamelCase__       =       f.read()

					# Imports of the form `import xxx`
					lowerCamelCase__       =       re.findall("^\s*import\s+(\S+)\s*$",     a,     flags=re.MULTILINE)
					# Imports of the form `from xxx import yyy`
					imports += re.findall("^\s*from\s+(\S+)\s+import",     a,     flags=re.MULTILINE)
					# Only keep the top-level module
					lowerCamelCase__       =       [imp.split(".")[0] for imp in imports if not imp.startswith(".")]

					# Unique-ify and test we got them all
					lowerCamelCase__       =       list(set(a))
					lowerCamelCase__       =       []
					for imp in imports:
										try:
															importlib.import_module(a)
										except ImportError:
															missing_packages.append(a)

					if len(a) > 0:
										raise ImportError(
										    "This modeling file requires the following packages that were not found in your environment: "
										    f"{', '.join(a)}. Run `pip install {' '.join(a)}`")

					return get_relative_imports(a)





def    __UpperCamelCase      (    a,     a) ->Union[str, Any]:
					lowerCamelCase__       =       module_path.replace(os.path.sep,     ".")
					lowerCamelCase__       =       importlib.import_module(a)

					if class_name is None:
										return find_pipeline_class(a)
					return getattr(a,     a)





def    __UpperCamelCase      (    a) ->Tuple:
					from ..pipelines import DiffusionPipeline

					lowerCamelCase__       =       dict(inspect.getmembers(a,     inspect.isclass))

					lowerCamelCase__       =       None
					for cls_name, cls in cls_members.items():
										if (
										    cls_name != DiffusionPipeline.__name__
										    and issubclass(cls,     a)
										    and cls.__module__.split(".")[0] != "diffusers"
										):
															if pipeline_class is not None:
																				raise ValueError(
																				    f"Multiple classes that inherit from {DiffusionPipeline.__name__} have been found:"
																				    f" {pipeline_class.__name__}, and {cls_name}. Please make sure to define only one in"
																				    f" {loaded_module}.")
															lowerCamelCase__       =       cls

					return pipeline_class





def    __UpperCamelCase      (    a,     a,     a = None,     a = False,     a = False,     a = None,     a = None,     a = None,     a = False,     ) ->Tuple:
					lowerCamelCase__       =       str(a)

					lowerCamelCase__       =       os.path.join(a,     a)

					if os.path.isfile(a):
										lowerCamelCase__       =       module_file_or_url
										lowerCamelCase__       =       "local"
					elif pretrained_model_name_or_path.count("/") == 0:
										lowerCamelCase__       =       get_diffusers_versions()
										# cut ".dev0"
										lowerCamelCase__       =       "v" + ".".join(__version__.split(".")[:3])

										# retrieve github version that matches
										if revision is None:
															lowerCamelCase__       =       latest_version if latest_version[1:] in available_versions else "main"
															logger.info(f"Defaulting to latest_version: {revision}.")
										elif revision in available_versions:
															lowerCamelCase__       =       f"v{revision}"
										elif revision == "main":
															lowerCamelCase__       =       revision
										else:
															raise ValueError(
															    f"`custom_revision`: {revision} does not exist. Please make sure to choose one of"
															    f" {', '.join(available_versions + ['main'])}.")

										# community pipeline on GitHub
										lowerCamelCase__       =       COMMUNITY_PIPELINES_URL.format(revision=a,     pipeline=a)
										try:
															lowerCamelCase__       =       cached_download(
															    a,     cache_dir=a,     force_download=a,     proxies=a,     resume_download=a,     local_files_only=a,     use_auth_token=a,     )
															lowerCamelCase__       =       "git"
															lowerCamelCase__       =       pretrained_model_name_or_path + ".py"
										except EnvironmentError:
															logger.error(f"Could not locate the {module_file} inside {pretrained_model_name_or_path}.")
															raise
					else:
										try:
															# Load from URL or cache if already cached
															lowerCamelCase__       =       hf_hub_download(
															    a,     a,     cache_dir=a,     force_download=a,     proxies=a,     resume_download=a,     local_files_only=a,     use_auth_token=a,     )
															lowerCamelCase__       =       os.path.join("local",     "--".join(pretrained_model_name_or_path.split("/")))
										except EnvironmentError:
															logger.error(f"Could not locate the {module_file} inside {pretrained_model_name_or_path}.")
															raise

    # Check we have all the requirements in our environment
					lowerCamelCase__       =       check_imports(a)

					# Now we move the module inside our cached dynamic modules.
					lowerCamelCase__       =       DIFFUSERS_DYNAMIC_MODULE_NAME + os.path.sep + submodule
					create_dynamic_module(a)
					lowerCamelCase__       =       Path(a) / full_submodule
					if submodule == "local" or submodule == "git":
										# We always copy local files (we could hash the file to see if there was a change, and give them the name of
										# that hash, to only copy when there is a modification but it seems overkill for now).
										# The only reason we do the copy is to avoid putting too many folders in sys.path.
										shutil.copy(a,     submodule_path / module_file)
										for module_needed in modules_needed:
															lowerCamelCase__       =       f"{module_needed}.py"
															shutil.copy(os.path.join(a,     a),     submodule_path / module_needed)
					else:
										# Get the commit hash
										# TODO: we will get this info in the etag soon, so retrieve it from there and not here.
										if isinstance(a,     a):
															lowerCamelCase__       =       use_auth_token
										elif use_auth_token is True:
															lowerCamelCase__       =       HfFolder.get_token()
										else:
															lowerCamelCase__       =       None

										lowerCamelCase__       =       model_info(a,     revision=a,     token=a).sha

										# The module file will end up being placed in a subfolder with the git hash of the repo. This way we get the
										# benefit of versioning.
										lowerCamelCase__       =       submodule_path / commit_hash
										lowerCamelCase__       =       full_submodule + os.path.sep + commit_hash
										create_dynamic_module(a)

										if not (submodule_path / module_file).exists():
															shutil.copy(a,     submodule_path / module_file)
										# Make sure we also have every file with relative
										for module_needed in modules_needed:
															if not (submodule_path / module_needed).exists():
																				get_cached_module_file(
																				    a,     f"{module_needed}.py",     cache_dir=a,     force_download=a,     resume_download=a,     proxies=a,     use_auth_token=a,     revision=a,     local_files_only=a,     )
					return os.path.join(a,     a)







def    __UpperCamelCase      (    a,     a,     a = None,     a = None,     a = False,     a = False,     a = None,     a = None,     a = None,     a = False,     **a,     ) ->List[Any]:
					lowerCamelCase__       =       get_cached_module_file(
					    a,     a,     cache_dir=a,     force_download=a,     resume_download=a,     proxies=a,     use_auth_token=a,     revision=a,     local_files_only=a,     )
					return get_class_in_module(a,     final_module.replace(".py",     ""))








A_												=     {str(digit): digit**5 for digit in range(1_0)}





def    __UpperCamelCase      (    a) ->int:
					return sum(DIGITS_FIFTH_POWER[digit] for digit in str(a))





def    __UpperCamelCase      (    ) ->int:
					return sum(
					    number
					    for number in range(1000,     1000000)
					    if number == digits_fifth_powers_sum(a))


if __name__ == "__main__":
						print(solution())

