


import argparse
import os

import torch

from transformers import FlavaImageCodebook, FlavaImageCodebookConfig





def 						_lowerCAmelCase							(     _lowerCAmelCase   ,						_lowerCAmelCase   ,						_lowerCAmelCase   ,						_lowerCAmelCase			)    ->						Any:


						'''simple docstring'''






						__snake_case				=		s.rsplit(_lowerCAmelCase   ,						_lowerCAmelCase			)
						return new.join(_lowerCAmelCase			)





def 						_lowerCAmelCase							(     _lowerCAmelCase			)    ->						Tuple:


						'''simple docstring'''






						return sum(param.float().sum() if "encoder.embeddings" not in key else 0 for key, param in state_dict.items()			)





def 						_lowerCAmelCase							(     _lowerCAmelCase			)    ->						Optional[int]:


						'''simple docstring'''






						__snake_case				=		{}

						__snake_case				=		["group_1", "group_2", "group_3", "group_4"]
						for key, value in state_dict.items():
												for group_key in group_keys:
																		if group_key in key:
																								__snake_case				=		key.replace(F'''{group_key}.'''   ,						F'''{group_key}.group.'''			)

												if "res_path" in key:
																		__snake_case				=		key.replace("res_path."   ,						"res_path.path."			)

												if key.endswith(".w"			):
																		__snake_case				=		rreplace(_lowerCAmelCase   ,						".w"   ,						".weight"   ,						1			)
												if key.endswith(".b"			):
																		__snake_case				=		rreplace(_lowerCAmelCase   ,						".b"   ,						".bias"   ,						1			)

												__snake_case				=		value.float()

						return upgrade





@torch.no_grad()
def 						_lowerCAmelCase							(     _lowerCAmelCase   ,						_lowerCAmelCase   ,						_lowerCAmelCase=None   ,						_lowerCAmelCase=True			)    ->						Dict:


						'''simple docstring'''






						from dall_e import Encoder

						__snake_case				=		Encoder()
						if os.path.exists(_lowerCAmelCase			):
												__snake_case				=		torch.load(_lowerCAmelCase			)
						else:
												__snake_case				=		torch.hub.load_state_dict_from_url(_lowerCAmelCase			)

						if isinstance(_lowerCAmelCase   ,						_lowerCAmelCase			):
												__snake_case				=		ckpt.state_dict()
						encoder.load_state_dict(_lowerCAmelCase			)

						if config_path is not None:
												__snake_case				=		FlavaImageCodebookConfig.from_pretrained(_lowerCAmelCase			)
						else:
												__snake_case				=		FlavaImageCodebookConfig()

						__snake_case				=		FlavaImageCodebook(_lowerCAmelCase			).eval()
						__snake_case				=		encoder.state_dict()

						__snake_case				=		upgrade_state_dict(_lowerCAmelCase			)
						hf_model.load_state_dict(_lowerCAmelCase			)
						__snake_case				=		hf_model.state_dict()
						__snake_case				=		count_parameters(_lowerCAmelCase			)
						__snake_case				=		count_parameters(_lowerCAmelCase			)

						assert torch.allclose(_lowerCAmelCase   ,						_lowerCAmelCase   ,						atol=1E-3			)

						if save_checkpoint:
												hf_model.save_pretrained(_lowerCAmelCase			)
						else:
												return hf_state_dict


if __name__ == "__main__":
	A				:       int      =  argparse.ArgumentParser()
	parser.add_argument('--pytorch_dump_folder_path', default=None, type=str, help='Path to the output PyTorch model.')
	parser.add_argument('--checkpoint_path', default=None, type=str, help='Path to flava checkpoint')
	parser.add_argument('--config_path', default=None, type=str, help='Path to hf config.json of model to convert')
	A				:       Dict      =  parser.parse_args()

	convert_dalle_checkpoint(args.checkpoint_path, args.pytorch_dump_folder_path, args.config_path)









import requests
from bsa import BeautifulSoup





def 						_lowerCAmelCase							(     _lowerCAmelCase = "AAPL"			)    ->						str:


						'''simple docstring'''






						__snake_case				=		F'''https://in.finance.yahoo.com/quote/{symbol}?s={symbol}'''
						__snake_case				=		BeautifulSoup(requests.get(_lowerCAmelCase			).text   ,						"html.parser"			)
						__snake_case				=		"My(6px) Pos(r) smartphone_Mt(6px)"
						return soup.find("div"   ,						class_=class_			).find("span"			).text


if __name__ == "__main__":
	for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
		print(f'''Current {symbol:<4} stock price is {stock_price(symbol):>8}''')





