


"""simple docstring"""







from typing import Optional

from torch import nn

from .transformer_ad import TransformeraDModel, TransformeraDModelOutput




class 			UpperCamelCase_     (			nn.Module):

	"""simple docstring"""





	def __init__(			self      :    Optional[int]      ,      UpperCAmelCase__      :    int = 1_6      ,      UpperCAmelCase__      :    int = 8_8      ,      UpperCAmelCase__      :    Optional[int] = None      ,      UpperCAmelCase__      :    int = 1      ,      UpperCAmelCase__      :    float = 0.0      ,      UpperCAmelCase__      :    int = 3_2      ,      UpperCAmelCase__      :    Optional[int] = None      ,      UpperCAmelCase__      :    bool = False      ,      UpperCAmelCase__      :    Optional[int] = None      ,      UpperCAmelCase__      :    Optional[int] = None      ,      UpperCAmelCase__      :    str = "geglu"      ,      UpperCAmelCase__      :    Optional[int] = None      ,      )	->     str:
						super().__init__()
						__SCREAMING_SNAKE_CASE						       =    nn.ModuleList(
						    [
						        TransformeraDModel(
						            num_attention_heads=UpperCAmelCase__      ,      attention_head_dim=UpperCAmelCase__      ,      in_channels=UpperCAmelCase__      ,      num_layers=UpperCAmelCase__      ,      dropout=UpperCAmelCase__      ,      norm_num_groups=UpperCAmelCase__      ,      cross_attention_dim=UpperCAmelCase__      ,      attention_bias=UpperCAmelCase__      ,      sample_size=UpperCAmelCase__      ,      num_vector_embeds=UpperCAmelCase__      ,      activation_fn=UpperCAmelCase__      ,      num_embeds_ada_norm=UpperCAmelCase__      ,      )
						        for _ in range(2       )
						    ]       )

						# Variables that can be set by a pipeline:

						# The ratio of transformer1 to transformer2's output states to be combined during inference
						__SCREAMING_SNAKE_CASE						       =    0.5

						# The shape of `encoder_hidden_states` is expected to be
						# `(batch_size, condition_lengths[0]+condition_lengths[1], num_features)`
						__SCREAMING_SNAKE_CASE						       =    [7_7, 2_5_7]

						# Which transformer to use to encode which condition.
						# E.g. `(1, 0)` means that we'll use `transformers[1](conditions[0])` and `transformers[0](conditions[1])`
						__SCREAMING_SNAKE_CASE						       =    [1, 0]




	def   UpperCAmelCase_				(			self      :    List[str]      ,      UpperCAmelCase__      :    Optional[int]      ,      UpperCAmelCase__      :    Any      ,      UpperCAmelCase__      :    List[str]=None      ,      UpperCAmelCase__      :    List[Any]=None      ,      UpperCAmelCase__      :    int=None      ,      UpperCAmelCase__      :    bool = True      ,      )	->     str:
						__SCREAMING_SNAKE_CASE						       =    hidden_states

						__SCREAMING_SNAKE_CASE						       =    []
						__SCREAMING_SNAKE_CASE						       =    0
						# attention_mask is not used yet
						for i in range(2       ):
											# for each of the two transformers, pass the corresponding condition tokens
											__SCREAMING_SNAKE_CASE						       =    encoder_hidden_states[:, tokens_start : tokens_start + self.condition_lengths[i]]
											__SCREAMING_SNAKE_CASE						       =    self.transformer_index_for_condition[i]
											__SCREAMING_SNAKE_CASE						       =    self.transformers[transformer_index](
											    UpperCAmelCase__      ,      encoder_hidden_states=UpperCAmelCase__      ,      timestep=UpperCAmelCase__      ,      cross_attention_kwargs=UpperCAmelCase__      ,      return_dict=UpperCAmelCase__      ,      )[0]
											encoded_states.append(encoded_state - input_states       )
											tokens_start += self.condition_lengths[i]

						__SCREAMING_SNAKE_CASE						       =    encoded_states[0] * self.mix_ratio + encoded_states[1] * (1 - self.mix_ratio)
						__SCREAMING_SNAKE_CASE						       =    output_states + input_states

						if not return_dict:
											return (output_states,)

						return TransformeraDModelOutput(sample=UpperCAmelCase__       )




"""simple docstring"""







from datetime import datetime

import requests




def        UpperCAmelCase__	(lowerCAmelCase_       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    "https://downloadgram.net/wp-json/wppress/video-downloader/video?url="
					__SCREAMING_SNAKE_CASE						       =    requests.get(base_url + url       ).json()[0]["urls"][0]["src"]
					return requests.get(lowerCAmelCase_       ).content


if __name__ == "__main__":
		a__    :							str            =					input('''Enter Video/IGTV url: ''').strip()
		a__    :							List[Any]            =					F"{datetime.now():%Y-%m-%d_%H:%M:%S}.mp4"
		with open(file_name, '''wb''') as fp:
				fp.write(download_video(url))
		print(F"Done. Video saved to disk as {file_name}.")
