
"""simple docstring"""




import re
import time
from typing import Optional

import IPython.display as disp

from ..trainer_callback import TrainerCallback
from ..trainer_utils import IntervalStrategy, has_length



def 					a__				(       snake_case__       )		->      Optional[Any]:
			lowerCamelCase       =      int(__lowerCAmelCase       )
			lowerCamelCase   ,     lowerCamelCase   ,     lowerCamelCase       =      t // 36_00, (t // 60) % 60, t % 60
			return F'{h}:{m:02d}:{s:02d}' if h != 0 else F'{m:02d}:{s:02d}'



def 					a__				(       snake_case__ ,				snake_case__ ,				snake_case__ ,				snake_case__ ,				snake_case__=3_00       )		->      Optional[Any]:
			return F'\n    <div>\n      {prefix}\n      <progress value=\'{value}\' max=\'{total}\' style=\'width:{width}px; height:20px; vertical-align: middle;\'></progress>\n      {label}\n    </div>\n    '



def 					a__				(       snake_case__       )		->      Tuple:
			lowerCamelCase       =      """<table border=\"1\" class=\"dataframe\">\n"""
			html_code += """  <thead>\n <tr style="text-align: left;">\n"""
			for i in items[0]:
						html_code += F'      <th>{i}</th>\n'
			html_code += "    </tr>\n  </thead>\n  <tbody>\n"
			for line in items[1:]:
						html_code += "    <tr>\n"
						for elt in line:
									lowerCamelCase       =      F'{elt:.6f}' if isinstance(__lowerCAmelCase ,				__lowerCAmelCase       ) else str(__lowerCAmelCase       )
									html_code += F'      <td>{elt}</td>\n'
						html_code += "    </tr>\n"
			html_code += "  </tbody>\n</table><p>"
			return html_code






class 					__magic_name__							:






				'''simple docstring'''
				__UpperCamelCase    						=		5
				__UpperCamelCase    						=		0.2





				def __init__( self	,				_a	,				_a = None	,				_a = True	,				_a = None	,				_a = 300	,				):





							"""simple docstring"""
							lowerCamelCase       =      total
							lowerCamelCase       =      """""" if prefix is None else prefix
							lowerCamelCase       =      leave
							lowerCamelCase       =      parent
							lowerCamelCase       =      width
							lowerCamelCase       =      None
							lowerCamelCase       =      None
							lowerCamelCase       =      None





				def      _lowerCAmelCase       ( self	,				_a	,				_a = False	,				_a = None				):





							"""simple docstring"""
							lowerCamelCase       =      value
							if comment is not None:
										lowerCamelCase       =      comment
							if self.last_value is None:
										lowerCamelCase       =      lowerCamelCase       =      time.time()
										lowerCamelCase       =      lowerCamelCase       =      value
										lowerCamelCase       =      lowerCamelCase       =      None
										lowerCamelCase       =      self.warmup
										lowerCamelCase       =      1
										self.update_bar(lowerCAmelCase_				)
							elif value <= self.last_value and not force_update:
										return
							elif force_update or self.first_calls > 0 or value >= min(self.last_value + self.wait_for	,				self.total				):
										if self.first_calls > 0:
													self.first_calls -= 1
										lowerCamelCase       =      time.time()
										lowerCamelCase       =      current_time - self.start_time
										# We could have value = self.start_value if the update is called twixe with the same start value.
										if value > self.start_value:
													lowerCamelCase       =      self.elapsed_time / (value - self.start_value)
										else:
													lowerCamelCase       =      None
										if value >= self.total:
													lowerCamelCase       =      self.total
													lowerCamelCase       =      None
													if not self.leave:
																self.close()
										elif self.average_time_per_item is not None:
													lowerCamelCase       =      self.average_time_per_item * (self.total - value)
										self.update_bar(lowerCAmelCase_				)
										lowerCamelCase       =      value
										lowerCamelCase       =      current_time
										if self.average_time_per_item is None:
													lowerCamelCase       =      1
										else:
													lowerCamelCase       =      max(int(self.update_every / self.average_time_per_item				)	,				1				)





				def      _lowerCAmelCase       ( self	,				_a	,				_a=None				):





							"""simple docstring"""
							lowerCamelCase       =      """ """ * (len(str(self.total				)				) - len(str(lowerCAmelCase_				)				)) + str(lowerCAmelCase_				)
							if self.elapsed_time is None:
										lowerCamelCase       =      f'[{spaced_value}/{self.total} : < :'
							elif self.predicted_remaining is None:
										lowerCamelCase       =      f'[{spaced_value}/{self.total} {format_time(self.elapsed_time				)}'
							else:
										lowerCamelCase       =      (
										    f'[{spaced_value}/{self.total} {format_time(self.elapsed_time				)} <'
										    f' {format_time(self.predicted_remaining				)}'
										)
										self.label += f', {1/self.average_time_per_item:.2f} it/s'
							self.label += "]" if self.comment is None or len(self.comment				) == 0 else f', {self.comment}]'
							self.display()





				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							lowerCamelCase       =      html_progress_bar(self.value	,				self.total	,				self.prefix	,				self.label	,				self.width				)
							if self.parent is not None:
										# If this is a child bar, the parent will take care of the display.
										self.parent.display()
										return
							if self.output is None:
										lowerCamelCase       =      disp.display(disp.HTML(self.html_code				)	,				display_id=lowerCAmelCase_				)
							else:
										self.output.update(disp.HTML(self.html_code				)				)





				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""







							if self.parent is None and self.output is not None:
										self.output.update(disp.HTML(""""""				)				)






class 					__magic_name__							( __UpperCAmelCase       ):






				'''simple docstring'''





				def __init__( self	,				_a	,				_a=None				):





							"""simple docstring"""
							super().__init__(lowerCAmelCase_				)
							lowerCamelCase       =      None if column_names is None else [column_names]
							lowerCamelCase       =      None





				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							lowerCamelCase       =      html_progress_bar(self.value	,				self.total	,				self.prefix	,				self.label	,				self.width				)
							if self.inner_table is not None:
										self.html_code += text_to_html_table(self.inner_table				)
							if self.child_bar is not None:
										self.html_code += self.child_bar.html_code
							if self.output is None:
										lowerCamelCase       =      disp.display(disp.HTML(self.html_code				)	,				display_id=lowerCAmelCase_				)
							else:
										self.output.update(disp.HTML(self.html_code				)				)





				def      _lowerCAmelCase       ( self	,				_a				):





							"""simple docstring"""







							if self.inner_table is None:
										lowerCamelCase       =      [list(values.keys()				), list(values.values()				)]
							else:
										lowerCamelCase       =      self.inner_table[0]
										if len(self.inner_table				) == 1:
													# We give a chance to update the column names at the first iteration
													for key in values.keys():
																if key not in columns:
																			columns.append(lowerCAmelCase_				)
													lowerCamelCase       =      columns
										self.inner_table.append([values[c] for c in columns]				)





				def      _lowerCAmelCase       ( self	,				_a	,				_a=None	,				_a=300				):





							"""simple docstring"""
							lowerCamelCase       =      NotebookProgressBar(lowerCAmelCase_	,				prefix=lowerCAmelCase_	,				parent=self	,				width=lowerCAmelCase_				)
							return self.child_bar





				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							lowerCamelCase       =      None
							self.display()






class 					__magic_name__							( __UpperCAmelCase       ):






				'''simple docstring'''





				def __init__( self				):





							"""simple docstring"""
							lowerCamelCase       =      None
							lowerCamelCase       =      None
							lowerCamelCase       =      False





				def      _lowerCAmelCase       ( self	,				_a	,				_a	,				_a	,				**_a				):





							"""simple docstring"""
							lowerCamelCase       =      """Epoch""" if args.evaluation_strategy == IntervalStrategy.EPOCH else """Step"""
							lowerCamelCase       =      0
							lowerCamelCase       =      0
							lowerCamelCase       =      [self.first_column] + ["""Training Loss"""]
							if args.evaluation_strategy != IntervalStrategy.NO:
										column_names.append("""Validation Loss"""				)
							lowerCamelCase       =      NotebookTrainingTracker(state.max_steps	,				lowerCAmelCase_				)





				def      _lowerCAmelCase       ( self	,				_a	,				_a	,				_a	,				**_a				):





							"""simple docstring"""
							lowerCamelCase       =      int(state.epoch				) if int(state.epoch				) == state.epoch else f'{state.epoch:.2f}'
							self.training_tracker.update(
							    state.global_step + 1	,				comment=f'Epoch {epoch}/{state.num_train_epochs}'	,				force_update=self._force_next_update	,				)
							lowerCamelCase       =      False





				def      _lowerCAmelCase       ( self	,				_a	,				_a	,				_a	,				_a=None	,				**_a				):





							"""simple docstring"""







							if not has_length(lowerCAmelCase_				):
										return
							if self.prediction_bar is None:
										if self.training_tracker is not None:
													lowerCamelCase       =      self.training_tracker.add_child(len(lowerCAmelCase_				)				)
										else:
													lowerCamelCase       =      NotebookProgressBar(len(lowerCAmelCase_				)				)
										self.prediction_bar.update(1				)
							else:
										self.prediction_bar.update(self.prediction_bar.value + 1				)





				def      _lowerCAmelCase       ( self	,				_a	,				_a	,				_a	,				**_a				):





							"""simple docstring"""







							if self.prediction_bar is not None:
										self.prediction_bar.close()
							lowerCamelCase       =      None





				def      _lowerCAmelCase       ( self	,				_a	,				_a	,				_a	,				_a=None	,				**_a				):





							"""simple docstring"""







							if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
										lowerCamelCase       =      {"""Training Loss""": logs["""loss"""]}
										# First column is necessarily Step sine we're not in epoch eval strategy
										lowerCamelCase       =      state.global_step
										self.training_tracker.write_line(lowerCAmelCase_				)





				def      _lowerCAmelCase       ( self	,				_a	,				_a	,				_a	,				_a=None	,				**_a				):





							"""simple docstring"""







							if self.training_tracker is not None:
										lowerCamelCase       =      {"""Training Loss""": """No log""", """Validation Loss""": """No log"""}
										for log in reversed(state.log_history				):
													if "loss" in log:
																lowerCamelCase       =      log["""loss"""]
																break

										if self.first_column == "Epoch":
													lowerCamelCase       =      int(state.epoch				)
										else:
													lowerCamelCase       =      state.global_step
										lowerCamelCase       =      """eval"""
										for k in metrics:
													if k.endswith("""_loss"""				):
																lowerCamelCase       =      re.sub(r"""\_loss$"""	,				""""""	,				lowerCAmelCase_				)
										lowerCamelCase       =      metrics.pop("""total_flos"""	,				lowerCAmelCase_				)
										lowerCamelCase       =      metrics.pop("""epoch"""	,				lowerCAmelCase_				)
										lowerCamelCase       =      metrics.pop(f'{metric_key_prefix}_runtime'	,				lowerCAmelCase_				)
										lowerCamelCase       =      metrics.pop(f'{metric_key_prefix}_samples_per_second'	,				lowerCAmelCase_				)
										lowerCamelCase       =      metrics.pop(f'{metric_key_prefix}_steps_per_second'	,				lowerCAmelCase_				)
										lowerCamelCase       =      metrics.pop(f'{metric_key_prefix}_jit_compilation_time'	,				lowerCAmelCase_				)
										for k, v in metrics.items():
													if k == f'{metric_key_prefix}_loss':
																lowerCamelCase       =      v
													else:
																lowerCamelCase       =      k.split("""_"""				)
																lowerCamelCase       =      """ """.join([part.capitalize() for part in splits[1:]]				)
																lowerCamelCase       =      v
										self.training_tracker.write_line(lowerCAmelCase_				)
										self.training_tracker.remove_child()
										lowerCamelCase       =      None
										# Evaluation takes a long time so we should force the next update.
										lowerCamelCase       =      True





				def      _lowerCAmelCase       ( self	,				_a	,				_a	,				_a	,				**_a				):





							"""simple docstring"""
							self.training_tracker.update(
							    state.global_step	,				comment=f'Epoch {int(state.epoch				)}/{state.num_train_epochs}'	,				force_update=lowerCAmelCase_				)
							lowerCamelCase       =      None









"""simple docstring"""




from __future__ import annotations

import json

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

lowerCAmelCase							:    List[Any]  							=							{"""UserAgent""": UserAgent().random}



def 					a__				(       snake_case__       )		->      dict:
			lowerCamelCase       =      script.contents[0]
			lowerCamelCase       =      json.loads(data[data.find("""{\"config\""""       ) : -1]       )
			return info["entry_data"]["ProfilePage"][0]["graphql"]["user"]






class 					__magic_name__							:






				'''simple docstring'''





				def __init__( self	,				_a				):





							"""simple docstring"""
							lowerCamelCase       =      f'https://www.instagram.com/{username}/'
							lowerCamelCase       =      self.get_json()





				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							lowerCamelCase       =      requests.get(self.url	,				headers=_a				).text
							lowerCamelCase       =      BeautifulSoup(_a	,				"""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				):





							"""simple docstring"""
							return f'{self.__class__.__name__}(\'{self.username}\')'





				def __str__( self				):





							"""simple docstring"""
							return f'{self.fullname} ({self.username}) is {self.biography}'





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return self.user_data["username"]





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return self.user_data["full_name"]





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return self.user_data["biography"]





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return self.user_data["business_email"]





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return self.user_data["external_url"]





				@property
				def      _lowerCAmelCase       ( self				):





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





				@property
				def      _lowerCAmelCase       ( self				):





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





				@property
				def      _lowerCAmelCase       ( self				):





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





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return self.user_data["profile_pic_url_hd"]





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return self.user_data["is_verified"]





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return self.user_data["is_private"]




def 					a__				(       snake_case__ = "github"       )		->      None:
			import os

			if os.environ.get("""CI"""       ):
						return  # test failing on GitHub Actions
			lowerCamelCase       =      InstagramUser(snake_case__       )
			assert instagram_user.user_data
			assert isinstance(instagram_user.user_data ,				snake_case__       )
			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 > 1_50
			assert instagram_user.number_of_followers > 12_00_00
			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							:    str  							=							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 = }""")



