


'''simple docstring'''


from typing import Union

import fire
import torch
from tqdm import tqdm






def        __lowerCAmelCase       (__lowerCAmelCase					,       __lowerCAmelCase = "cpu"					,       __lowerCAmelCase = None      ):
		_UpperCAmelCase						:				List[Any]	    =					torch.load(__lowerCAmelCase					,       map_location=__lowerCAmelCase      )
		for k, v in tqdm(state_dict.items()      ):
				if not isinstance(__lowerCAmelCase					,       torch.Tensor      ):
						raise TypeError("FP16 conversion only works on paths that are saved state dicts, like pytorch_model.bin"      )
				_UpperCAmelCase						:				Any	    =					v.half()
		if save_path is None:  # overwrite src_path
				_UpperCAmelCase						:				Optional[int]	    =					src_path
		torch.save(__lowerCAmelCase					,       __lowerCAmelCase      )


if __name__ == "__main__":
						fire.Fire(convert)







'''simple docstring'''


from __future__ import annotations

import json

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

lowerCamelCase__					=   {'UserAgent': UserAgent().random}






def        __lowerCAmelCase       (__lowerCAmelCase      ):
		_UpperCAmelCase						:				List[str]	    =					script.contents[0]
		_UpperCAmelCase						:				Any	    =					json.loads(data[data.find("{\"config\""      ) : -1]      )
		return info["entry_data"]["ProfilePage"][0]["graphql"]["user"]






class 		lowerCAmelCase__	:




			def __init__(						self     :   str		,     lowerCamelCase__     :   List[Any]       )      ->List[str]:



					'''simple docstring'''







					_UpperCAmelCase						:				List[Any]	    =					F"""https://www.instagram.com/{username}/"""
					_UpperCAmelCase						:				Dict	    =					self.get_json()




			def 							lowerCAmelCase__			(						self     :   Any       )      ->dict:



					'''simple docstring'''







					_UpperCAmelCase						:				Optional[int]	    =					requests.get(self.url		,     headers=lowerCamelCase__       ).text
					_UpperCAmelCase						:				Any	    =					BeautifulSoup(lowerCamelCase__		,     "html.parser"       ).find_all("script"       )
					try:
							return extract_user_profile(scripts[4]       )
					except (json.decoder.JSONDecodeError, KeyError):
							return extract_user_profile(scripts[3]       )




			def __repr__(						self     :   Optional[Any]       )      ->str:



					'''simple docstring'''







					return F"""{self.__class__.__name__}('{self.username}')"""




			def __str__(						self     :   List[Any]       )      ->str:



					'''simple docstring'''







					return F"""{self.fullname} ({self.username}) is {self.biography}"""




			@property
			def 							lowerCAmelCase__			(						self     :   Optional[int]       )      ->str:



					'''simple docstring'''







					return self.user_data["username"]




			@property
			def 							lowerCAmelCase__			(						self     :   Optional[int]       )      ->str:



					'''simple docstring'''







					return self.user_data["full_name"]




			@property
			def 							lowerCAmelCase__			(						self     :   Optional[int]       )      ->str:



					'''simple docstring'''







					return self.user_data["biography"]




			@property
			def 							lowerCAmelCase__			(						self     :   int       )      ->str:



					'''simple docstring'''







					return self.user_data["business_email"]




			@property
			def 							lowerCAmelCase__			(						self     :   str       )      ->str:



					'''simple docstring'''







					return self.user_data["external_url"]




			@property
			def 							lowerCAmelCase__			(						self     :   Tuple       )      ->int:



					'''simple docstring'''







					return self.user_data["edge_followed_by"]["count"]




			@property
			def 							lowerCAmelCase__			(						self     :   str       )      ->int:



					'''simple docstring'''







					return self.user_data["edge_follow"]["count"]




			@property
			def 							lowerCAmelCase__			(						self     :   Any       )      ->int:



					'''simple docstring'''







					return self.user_data["edge_owner_to_timeline_media"]["count"]




			@property
			def 							lowerCAmelCase__			(						self     :   List[Any]       )      ->str:



					'''simple docstring'''







					return self.user_data["profile_pic_url_hd"]




			@property
			def 							lowerCAmelCase__			(						self     :   Optional[Any]       )      ->bool:



					'''simple docstring'''







					return self.user_data["is_verified"]






			@property
			def 							lowerCAmelCase__			(						self     :   int       )      ->bool:



					'''simple docstring'''







					return self.user_data["is_private"]






def        __lowerCAmelCase       (__lowerCAmelCase = "github"      ):
		import os

		if os.environ.get("CI"      ):
				return  # test failing on GitHub Actions
		_UpperCAmelCase						:				Dict	    =					InstagramUser(__lowerCAmelCase      )
		assert instagram_user.user_data
		assert isinstance(instagram_user.user_data					,       __lowerCAmelCase      )
		assert instagram_user.username == username
		if username != "github":
				return
		assert instagram_user.fullname == "GitHub"
		assert instagram_user.biography == "Built for developers."
		assert instagram_user.number_of_posts > 150
		assert instagram_user.number_of_followers > 120_000
		assert instagram_user.number_of_followings > 15
		assert instagram_user.email == "support@github.com"
		assert instagram_user.website == "https://github.com/readme"
		assert instagram_user.profile_picture_url.startswith("https://instagram."      )
		assert instagram_user.is_verified is True
		assert instagram_user.is_private is False


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						lowerCamelCase__					=   InstagramUser('github')
						print(instagram_user)
						print(F'''{instagram_user.number_of_posts = }''')
						print(F'''{instagram_user.number_of_followers = }''')
						print(F'''{instagram_user.number_of_followings = }''')
						print(F'''{instagram_user.email = }''')
						print(F'''{instagram_user.website = }''')
						print(F'''{instagram_user.profile_picture_url = }''')
						print(F'''{instagram_user.is_verified = }''')
						print(F'''{instagram_user.is_private = }''')



