


'''simple docstring'''


from typing import Any, Dict, List, Union

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, ChunkPipeline


if is_vision_available():
						from PIL import Image

						from ..image_utils import load_image

if is_torch_available():
						import torch

						from transformers.modeling_outputs import BaseModelOutput

						from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING

lowerCamelCase__					=   logging.get_logger(__name__)






@add_end_docstrings(UpperCAmelCase__		)
class 		lowerCAmelCase__	(	UpperCAmelCase__		):




			def __init__(						self     :   Dict		,     **lowerCamelCase__     :   Dict       )      ->Tuple:



					'''simple docstring'''







					super().__init__(**lowerCamelCase__       )

					if self.framework == "tf":
							raise ValueError(F"""The {self.__class__} is only available in PyTorch."""       )

					requires_backends(self		,     "vision"       )
					self.check_model_type(lowerCamelCase__       )




			def __call__(						self     :   List[str]		,     lowerCamelCase__     :   Union[str, "Image.Image", List[Dict[str, Any]]]		,     lowerCamelCase__     :   Union[str, List[str]] = None		,     **lowerCamelCase__     :   Optional[int]		,     )      ->List[Any]:



					'''simple docstring'''







					if "text_queries" in kwargs:
							_UpperCAmelCase						:				Optional[Any]	    =					kwargs.pop("text_queries"       )

					if isinstance(lowerCamelCase__		,     (str, Image.Image)       ):
							_UpperCAmelCase						:				List[Any]	    =					{"image": image, "candidate_labels": candidate_labels}
					else:
							_UpperCAmelCase						:				Dict	    =					image
					_UpperCAmelCase						:				Dict	    =					super().__call__(lowerCamelCase__		,     **lowerCamelCase__       )
					return results




			def 							lowerCAmelCase__			(						self     :   List[Any]		,     **lowerCamelCase__     :   Dict       )      ->str:



					'''simple docstring'''







					_UpperCAmelCase						:				str	    =					{}
					if "threshold" in kwargs:
							_UpperCAmelCase						:				Optional[Any]	    =					kwargs["threshold"]
					if "top_k" in kwargs:
							_UpperCAmelCase						:				List[str]	    =					kwargs["top_k"]
					return {}, {}, postprocess_params




			def 							lowerCAmelCase__			(						self     :   Optional[int]		,     lowerCamelCase__     :   str       )      ->Optional[Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				Dict	    =					load_image(inputs["image"]       )
					_UpperCAmelCase						:				Union[str, Any]	    =					inputs["candidate_labels"]
					if isinstance(lowerCamelCase__		,     lowerCamelCase__       ):
							_UpperCAmelCase						:				Any	    =					candidate_labels.split(","       )

					_UpperCAmelCase						:				str	    =					torch.tensor([[image.height, image.width]]		,     dtype=torch.intaa       )
					for i, candidate_label in enumerate(lowerCamelCase__       ):
							_UpperCAmelCase						:				Tuple	    =					self.tokenizer(lowerCamelCase__		,     return_tensors=self.framework       )
							_UpperCAmelCase						:				List[str]	    =					self.image_processor(lowerCamelCase__		,     return_tensors=self.framework       )
							yield {
							    "is_last": i == len(lowerCamelCase__       ) - 1,
							    "target_size": target_size,
							    "candidate_label": candidate_label,
							    **text_inputs,
							    **image_features,
							}




			def 							lowerCAmelCase__			(						self     :   Optional[int]		,     lowerCamelCase__     :   str       )      ->Union[str, Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				List[Any]	    =					model_inputs.pop("target_size"       )
					_UpperCAmelCase						:				Optional[int]	    =					model_inputs.pop("candidate_label"       )
					_UpperCAmelCase						:				Union[str, Any]	    =					model_inputs.pop("is_last"       )

					_UpperCAmelCase						:				Union[str, Any]	    =					self.model(**lowerCamelCase__       )

					_UpperCAmelCase						:				Optional[Any]	    =					{"target_size": target_size, "candidate_label": candidate_label, "is_last": is_last, **outputs}
					return model_outputs




			def 							lowerCAmelCase__			(						self     :   Union[str, Any]		,     lowerCamelCase__     :   Union[str, Any]		,     lowerCamelCase__     :   List[str]=0.1		,     lowerCamelCase__     :   Optional[int]=None       )      ->int:



					'''simple docstring'''







					_UpperCAmelCase						:				Any	    =					[]
					for model_output in model_outputs:
							_UpperCAmelCase						:				Union[str, Any]	    =					model_output["candidate_label"]
							_UpperCAmelCase						:				Tuple	    =					BaseModelOutput(lowerCamelCase__       )
							_UpperCAmelCase						:				Dict	    =					self.image_processor.post_process_object_detection(
							    outputs=lowerCamelCase__		,     threshold=lowerCamelCase__		,     target_sizes=model_output["target_size"]       )[0]

							for index in outputs["scores"].nonzero():
									_UpperCAmelCase						:				int	    =					outputs["scores"][index].item()
									_UpperCAmelCase						:				Optional[int]	    =					self._get_bounding_box(outputs["boxes"][index][0]       )

									_UpperCAmelCase						:				Tuple	    =					{"score": score, "label": label, "box": box}
									results.append(lowerCamelCase__       )

					_UpperCAmelCase						:				List[str]	    =					sorted(lowerCamelCase__		,     key=lambda lowerCamelCase__       : x["score"]		,     reverse=lowerCamelCase__       )
					if top_k:
							_UpperCAmelCase						:				Tuple	    =					results[:top_k]

					return results






			def 							lowerCAmelCase__			(						self     :   str		,     lowerCamelCase__     :   "torch.Tensor"       )      ->Dict[str, int]:



					'''simple docstring'''







					if self.framework != "pt":
							raise ValueError("The ZeroShotObjectDetectionPipeline is only available in PyTorch."       )
					_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase						:				List[str]	    =					box.int().tolist()
					_UpperCAmelCase						:				Tuple	    =					{
					    "xmin": xmin,
					    "ymin": ymin,
					    "xmax": xmax,
					    "ymax": ymax,
					}
					return bbox







'''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 = }''')



