



import glob
import os
from typing import Dict, List, Union

import torch

from diffusers.utils import is_safetensors_available


if is_safetensors_available():
						import safetensors.torch

from huggingface_hub import snapshot_download

from diffusers import DiffusionPipeline, __version__
from diffusers.schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME
from diffusers.utils import CONFIG_NAME, DIFFUSERS_CACHE, ONNX_WEIGHTS_NAME, WEIGHTS_NAME





class 		__SCREAMING_SNAKE_CASE      (				snake_case__      ):






				"""simple docstring"""

				def __init__(				self      ):






					"""simple docstring"""

					self.register_to_config()
					super().__init__()







				def 		__lowerCamelCase(				self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					if dicta == dicta:
						return True
					else:
						_snake_case					:							Optional[int]					     =   self._remove_meta_keys(lowercase_      )
						_snake_case					:							Union[str, Any]					     =   self._remove_meta_keys(lowercase_      )
						if configa == configa:
							print(f'''Warning !: Mismatch in keys {meta_keysa} and {meta_keysa}.'''      )
							return True
					return False







				def 		__lowerCamelCase(				self						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					_snake_case					:							Optional[Any]					     =   []
					_snake_case					:							str					     =   config_dict.copy()
					for key in config_dict.keys():
						if key.startswith("""_"""      ):
							temp_dict.pop(lowercase_      )
							meta_keys.append(lowercase_      )
					return (temp_dict, meta_keys)







				@torch.no_grad()
				def 		__lowerCamelCase(				self						,	SCREAMING_SNAKE_CASE__						,	**SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					_snake_case					:							List[str]					     =   kwargs.pop("""cache_dir"""						,	lowercase_      )
					_snake_case					:							int					     =   kwargs.pop("""resume_download"""						,	lowercase_      )
					_snake_case					:							str					     =   kwargs.pop("""force_download"""						,	lowercase_      )
					_snake_case					:							Tuple					     =   kwargs.pop("""proxies"""						,	lowercase_      )
					_snake_case					:							Any					     =   kwargs.pop("""local_files_only"""						,	lowercase_      )
					_snake_case					:							List[str]					     =   kwargs.pop("""use_auth_token"""						,	lowercase_      )
					_snake_case					:							Any					     =   kwargs.pop("""revision"""						,	lowercase_      )
					_snake_case					:							str					     =   kwargs.pop("""torch_dtype"""						,	lowercase_      )
					_snake_case					:							Optional[int]					     =   kwargs.pop("""device_map"""						,	lowercase_      )

					_snake_case					:							str					     =   kwargs.pop("""alpha"""						,	0.5      )
					_snake_case					:							Any					     =   kwargs.pop("""interp"""						,	lowercase_      )

					print("""Received list"""						,	lowercase_      )
					print(f'''Combining with alpha={alpha}, interpolation mode={interp}'''      )

					_snake_case					:							List[str]					     =   len(lowercase_      )
					# Ignore result from model_index_json comparision of the two checkpoints
					_snake_case					:							str					     =   kwargs.pop("""force"""						,	lowercase_      )

					# If less than 2 checkpoints, nothing to merge. If more than 3, not supported for now.
					if checkpoint_count > 3 or checkpoint_count < 2:
						raise ValueError(
						    """Received incorrect number of checkpoints to merge. Ensure that either 2 or 3 checkpoints are being"""
						    """ passed."""      )

					print("""Received the right number of checkpoints"""      )
					# chkpt0, chkpt1 = pretrained_model_name_or_path_list[0:2]
					# chkpt2 = pretrained_model_name_or_path_list[2] if checkpoint_count == 3 else None

					# Validate that the checkpoints can be merged
					# Step 1: Load the model config and compare the checkpoints. We'll compare the model_index.json first while ignoring the keys starting with '_'
					_snake_case					:							str					     =   []
					for pretrained_model_name_or_path in pretrained_model_name_or_path_list:
						_snake_case					:							List[str]					     =   DiffusionPipeline.load_config(
						    lowercase_						,	cache_dir=lowercase_						,	resume_download=lowercase_						,	force_download=lowercase_						,	proxies=lowercase_						,	local_files_only=lowercase_						,	use_auth_token=lowercase_						,	revision=lowercase_						,	)
						config_dicts.append(lowercase_      )

					_snake_case					:							Union[str, Any]					     =   True
					for idx in range(1						,	len(lowercase_      )      ):
						comparison_result &= self._compare_model_configs(config_dicts[idx - 1]						,	config_dicts[idx]      )
						if not force and comparison_result is False:
							raise ValueError("""Incompatible checkpoints. Please check model_index.json for the models."""      )
							print(config_dicts[0]						,	config_dicts[1]      )
					print("""Compatible model_index.json files found"""      )
					# Step 2: Basic Validation has succeeded. Let's download the models and save them into our local files.
					_snake_case					:							Optional[Any]					     =   []
					for pretrained_model_name_or_path, config_dict in zip(lowercase_						,	lowercase_      ):
						_snake_case					:							str					     =   [k for k in config_dict.keys() if not k.startswith("""_"""      )]
						_snake_case					:							str					     =   [os.path.join(lowercase_						,	"""*"""      ) for k in folder_names]
						allow_patterns += [
						    WEIGHTS_NAME,
						    SCHEDULER_CONFIG_NAME,
						    CONFIG_NAME,
						    ONNX_WEIGHTS_NAME,
						    DiffusionPipeline.config_name,
						]
						_snake_case					:							List[Any]					     =   config_dict.get("""_class_name"""      )
						_snake_case					:							Optional[int]					     =   {'''diffusers''': __version__, '''pipeline_class''': requested_pipeline_class}

						_snake_case					:							Union[str, Any]					     =   (
						    pretrained_model_name_or_path
						    if os.path.isdir(lowercase_      )
						    else snapshot_download(
						        lowercase_						,	cache_dir=lowercase_						,	resume_download=lowercase_						,	proxies=lowercase_						,	local_files_only=lowercase_						,	use_auth_token=lowercase_						,	revision=lowercase_						,	allow_patterns=lowercase_						,	user_agent=lowercase_						,	)
						)
						print("""Cached Folder"""						,	lowercase_      )
						cached_folders.append(lowercase_      )

					# Step 3:-
					# Load the first checkpoint as a diffusion pipeline and modify its module state_dict in place
					_snake_case					:							Any					     =   DiffusionPipeline.from_pretrained(
					    cached_folders[0]						,	torch_dtype=lowercase_						,	device_map=lowercase_      )
					final_pipe.to(self.device      )

					_snake_case					:							Dict					     =   None
					if len(lowercase_      ) > 2:
						_snake_case					:							Dict					     =   os.path.join(cached_folders[2]      )

					if interp == "sigmoid":
						_snake_case					:							str					     =   CheckpointMergerPipeline.sigmoid
					elif interp == "inv_sigmoid":
						_snake_case					:							int					     =   CheckpointMergerPipeline.inv_sigmoid
					elif interp == "add_diff":
						_snake_case					:							Optional[Any]					     =   CheckpointMergerPipeline.add_difference
					else:
						_snake_case					:							str					     =   CheckpointMergerPipeline.weighted_sum

					# Find each module's state dict.
					for attr in final_pipe.config.keys():
						if not attr.startswith("""_"""      ):
							_snake_case					:							Union[str, Any]					     =   os.path.join(cached_folders[1]						,	lowercase_      )
							if os.path.exists(lowercase_      ):
								_snake_case					:							str					     =   [
								    *glob.glob(os.path.join(lowercase_						,	"""*.safetensors"""      )      ),
								    *glob.glob(os.path.join(lowercase_						,	"""*.bin"""      )      ),
								]
								_snake_case					:							str					     =   files[0] if len(lowercase_      ) > 0 else None
							if len(lowercase_      ) < 3:
								_snake_case					:							List[Any]					     =   None
							else:
								_snake_case					:							str					     =   os.path.join(cached_folders[2]						,	lowercase_      )
								if os.path.exists(lowercase_      ):
									_snake_case					:							Union[str, Any]					     =   [
									    *glob.glob(os.path.join(lowercase_						,	"""*.safetensors"""      )      ),
									    *glob.glob(os.path.join(lowercase_						,	"""*.bin"""      )      ),
									]
									_snake_case					:							Dict					     =   files[0] if len(lowercase_      ) > 0 else None
                # For an attr if both checkpoint_path_1 and 2 are None, ignore.
                # If atleast one is present, deal with it according to interp method, of course only if the state_dict keys match.
							if checkpoint_path_a is None and checkpoint_path_a is None:
								print(f'''Skipping {attr}: not present in 2nd or 3d model'''      )
								continue
							try:
								_snake_case					:							Optional[int]					     =   getattr(lowercase_						,	lowercase_      )
								if isinstance(lowercase_						,	lowercase_      ):  # ignore requires_safety_checker boolean
									continue
								_snake_case					:							Any					     =   getattr(lowercase_						,	"""state_dict"""      )
								_snake_case					:							Union[str, Any]					     =   theta_a()

								_snake_case					:							List[Any]					     =   getattr(lowercase_						,	"""load_state_dict"""      )
								_snake_case					:							List[Any]					     =   (
								    safetensors.torch.load_file(lowercase_      )
								    if (is_safetensors_available() and checkpoint_path_a.endswith(""".safetensors"""      ))
								    else torch.load(lowercase_						,	map_location="""cpu"""      )
								)
								_snake_case					:							int					     =   None
								if checkpoint_path_a:
									_snake_case					:							Tuple					     =   (
									    safetensors.torch.load_file(lowercase_      )
									    if (is_safetensors_available() and checkpoint_path_a.endswith(""".safetensors"""      ))
									    else torch.load(lowercase_						,	map_location="""cpu"""      )
									)

								if not theta_a.keys() == theta_a.keys():
									print(f'''Skipping {attr}: key mismatch'''      )
									continue
								if theta_a and not theta_a.keys() == theta_a.keys():
									print(f'''Skipping {attr}:y mismatch'''      )
							except Exception as e:
								print(f'''Skipping {attr} do to an unexpected error: {str(lowercase_      )}'''      )
								continue
							print(f'''MERGING {attr}'''      )

							for key in theta_a.keys():
								if theta_a:
									_snake_case					:							Dict					     =   theta_func(theta_a[key]						,	theta_a[key]						,	theta_a[key]						,	lowercase_      )
								else:
									_snake_case					:							Union[str, Any]					     =   theta_func(theta_a[key]						,	theta_a[key]						,	lowercase_						,	lowercase_      )

							del theta_a
							del theta_a
							update_theta_a(lowercase_      )

							del theta_a
					return final_pipe







				@staticmethod
				def 		__lowerCamelCase(				SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					return ((1 - alpha) * thetaa) + (alpha * thetaa)







				@staticmethod
				def 		__lowerCamelCase(				SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					_snake_case					:							str					     =   alpha * alpha * (3 - (2 * alpha))
					return thetaa + ((thetaa - thetaa) * alpha)







				@staticmethod
				def 		__lowerCamelCase(				SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					import math

					_snake_case					:							int					     =   0.5 - math.sin(math.asin(1.0 - 2.0 * alpha      ) / 3.0      )
					return thetaa + ((thetaa - thetaa) * alpha)







				@staticmethod
				def 		__lowerCamelCase(				SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					return thetaa + (thetaa - thetaa) * (1.0 - alpha)








"""simple docstring"""





import requests
from bsa import BeautifulSoup



def 							_lowerCAmelCase   (    UpperCAmelCase  :				int   ,				UpperCAmelCase  :				str					):


					'''simple docstring'''






					UpperCamelCase__		:     Any								=(
					    '''https://www.horoscope.com/us/horoscopes/general/'''
					    F'''horoscope-general-daily-{day}.aspx?sign={zodiac_sign}'''
					)
					UpperCamelCase__		:     List[str]								=BeautifulSoup(requests.get(UpperCAmelCase					).content   ,				'''html.parser'''					)
					return soup.find('''div'''   ,				class_='''main-horoscope'''					).p.text


if __name__ == "__main__":
				print("""Daily Horoscope. \n""")
				print(
				    """enter your Zodiac sign number:\n""",
				    """1. Aries\n""",
				    """2. Taurus\n""",
				    """3. Gemini\n""",
				    """4. Cancer\n""",
				    """5. Leo\n""",
				    """6. Virgo\n""",
				    """7. Libra\n""",
				    """8. Scorpio\n""",
				    """9. Sagittarius\n""",
				    """10. Capricorn\n""",
				    """11. Aquarius\n""",
				    """12. Pisces\n""",
				)
				_SCREAMING_SNAKE_CASE							:	Any										=			int(input("""number> """).strip())
				print("""choose some day:\n""", """yesterday\n""", """today\n""", """tomorrow\n""")
				_SCREAMING_SNAKE_CASE							:	List[str]										=			input("""enter the day> """)
				_SCREAMING_SNAKE_CASE							:	Dict										=			horoscope(zodiac_sign, day)
				print(horoscope_text)


