

import gc
import unittest

import numpy as np
import torch
import torch.nn.functional as F
from transformers import (
    ClapTextConfig,
    ClapTextModelWithProjection,
    RobertaTokenizer,
    SpeechTaHifiGan,
    SpeechTaHifiGanConfig,
)

from diffusers import (
    AudioLDMPipeline,
    AutoencoderKL,
    DDIMScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    UNetaDConditionModel,
)
from diffusers.utils import is_xformers_available, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from ..pipeline_params import TEXT_TO_AUDIO_BATCH_PARAMS, TEXT_TO_AUDIO_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()







class        a__       (   UpperCAmelCase	,			unittest.TestCase       ):







  """simple docstring"""




  UpperCAmelCase__      : List[str]			       =AudioLDMPipeline
  UpperCAmelCase__      : List[str]			       =TEXT_TO_AUDIO_PARAMS
  UpperCAmelCase__      : List[str]			       =TEXT_TO_AUDIO_BATCH_PARAMS
  UpperCAmelCase__      : int			       =frozenset(
      [
          """num_inference_steps""",
          """num_waveforms_per_prompt""",
          """generator""",
          """latents""",
          """output_type""",
          """return_dict""",
          """callback""",
          """callback_steps""",
      ]       )


  def  _lowercase      (			self    : List[Any]		)					->Dict:
        """simple docstring"""







        torch.manual_seed(0		)
        SCREAMING_SNAKE_CASE :      List[str]       =   UNetaDConditionModel(
            block_out_channels=(3_2, 6_4)				,				layers_per_block=2				,				sample_size=3_2				,				in_channels=4				,				out_channels=4				,				down_block_types=("""DownBlock2D""", """CrossAttnDownBlock2D""")				,				up_block_types=("""CrossAttnUpBlock2D""", """UpBlock2D""")				,				cross_attention_dim=(3_2, 6_4)				,				class_embed_type="""simple_projection"""				,				projection_class_embeddings_input_dim=3_2				,				class_embeddings_concat=UpperCAmelCase__				,				)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   DDIMScheduler(
            beta_start=0.0_00_85				,				beta_end=0.0_12				,				beta_schedule="""scaled_linear"""				,				clip_sample=UpperCAmelCase__				,				set_alpha_to_one=UpperCAmelCase__				,				)
        torch.manual_seed(0		)
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   AutoencoderKL(
            block_out_channels=[3_2, 6_4]				,				in_channels=1				,				out_channels=1				,				down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]				,				up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]				,				latent_channels=4				,				)
        torch.manual_seed(0		)
        SCREAMING_SNAKE_CASE :      Optional[int]       =   ClapTextConfig(
            bos_token_id=0				,				eos_token_id=2				,				hidden_size=3_2				,				intermediate_size=3_7				,				layer_norm_eps=1e-05				,				num_attention_heads=4				,				num_hidden_layers=5				,				pad_token_id=1				,				vocab_size=1_0_0_0				,				projection_dim=3_2				,				)
        SCREAMING_SNAKE_CASE :      Dict       =   ClapTextModelWithProjection(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      List[str]       =   RobertaTokenizer.from_pretrained("""hf-internal-testing/tiny-random-roberta"""				,				model_max_length=7_7		)

        SCREAMING_SNAKE_CASE :      int       =   SpeechTaHifiGanConfig(
            model_in_dim=8				,				sampling_rate=1_6_0_0_0				,				upsample_initial_channel=1_6				,				upsample_rates=[2, 2]				,				upsample_kernel_sizes=[4, 4]				,				resblock_kernel_sizes=[3, 7]				,				resblock_dilation_sizes=[[1, 3, 5], [1, 3, 5]]				,				normalize_before=UpperCAmelCase__				,				)

        SCREAMING_SNAKE_CASE :      int       =   SpeechTaHifiGan(UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      Tuple       =   {
            """unet""": unet,
            """scheduler""": scheduler,
            """vae""": vae,
            """text_encoder""": text_encoder,
            """tokenizer""": tokenizer,
            """vocoder""": vocoder,
        }
        return components


  def  _lowercase      (			self    : Optional[int]				,				UpperCAmelCase__    : Union[str, Any]				,				UpperCAmelCase__    : Dict=0		)					->Optional[int]:
        """simple docstring"""







        if str(UpperCAmelCase__		).startswith("""mps"""		):
              SCREAMING_SNAKE_CASE :      Dict       =   torch.manual_seed(UpperCAmelCase__		)
        else:
              SCREAMING_SNAKE_CASE :      int       =   torch.Generator(device=UpperCAmelCase__		).manual_seed(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      str       =   {
            """prompt""": """A hammer hitting a wooden surface""",
            """generator""": generator,
            """num_inference_steps""": 2,
            """guidance_scale""": 6.0,
        }
        return inputs


  def  _lowercase      (			self    : Dict		)					->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      List[Any]       =   """cpu"""  # ensure determinism for the device-dependent torch.Generator

        SCREAMING_SNAKE_CASE :      Dict       =   self.get_dummy_components()
        SCREAMING_SNAKE_CASE :      str       =   AudioLDMPipeline(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Any       =   audioldm_pipe.to(UpperCAmelCase__		)
        audioldm_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      int       =   self.get_dummy_inputs(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Any       =   audioldm_pipe(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Any       =   output.audios[0]

        assert audio.ndim == 1
        assert len(UpperCAmelCase__		) == 2_5_6

        SCREAMING_SNAKE_CASE :      List[Any]       =   audio[:1_0]
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   np.array(
            [-0.00_50, 0.00_50, -0.00_60, 0.00_33, -0.00_26, 0.00_33, -0.00_27, 0.00_33, -0.00_28, 0.00_33]		)

        assert np.abs(audio_slice - expected_slice		).max() < 1e-2


  def  _lowercase      (			self    : int		)					->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   self.get_dummy_components()
        SCREAMING_SNAKE_CASE :      Optional[int]       =   AudioLDMPipeline(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      int       =   audioldm_pipe.to(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      int       =   audioldm_pipe.to(UpperCAmelCase__		)
        audioldm_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      Dict       =   self.get_dummy_inputs(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      int       =   3 * [inputs["""prompt"""]]

        # forward
        SCREAMING_SNAKE_CASE :      Tuple       =   audioldm_pipe(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Any       =   output.audios[0]

        SCREAMING_SNAKE_CASE :      int       =   self.get_dummy_inputs(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      int       =   3 * [inputs.pop("""prompt"""		)]

        SCREAMING_SNAKE_CASE :      Any       =   audioldm_pipe.tokenizer(
            UpperCAmelCase__				,				padding="""max_length"""				,				max_length=audioldm_pipe.tokenizer.model_max_length				,				truncation=UpperCAmelCase__				,				return_tensors="""pt"""				,				)
        SCREAMING_SNAKE_CASE :      Optional[int]       =   text_inputs["""input_ids"""].to(UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      List[Any]       =   audioldm_pipe.text_encoder(
            UpperCAmelCase__				,				)
        SCREAMING_SNAKE_CASE :      str       =   prompt_embeds.text_embeds
        # additional L_2 normalization over each hidden-state
        SCREAMING_SNAKE_CASE :      Tuple       =   F.normalize(UpperCAmelCase__				,				dim=-1		)

        SCREAMING_SNAKE_CASE :      List[str]       =   prompt_embeds

        # forward
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   audioldm_pipe(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   output.audios[0]

        assert np.abs(audio_a - audio_a		).max() < 1e-2


  def  _lowercase      (			self    : Tuple		)					->str:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      str       =   self.get_dummy_components()
        SCREAMING_SNAKE_CASE :      List[str]       =   AudioLDMPipeline(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Dict       =   audioldm_pipe.to(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Dict       =   audioldm_pipe.to(UpperCAmelCase__		)
        audioldm_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      str       =   self.get_dummy_inputs(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      int       =   3 * ["""this is a negative prompt"""]
        SCREAMING_SNAKE_CASE :      Tuple       =   negative_prompt
        SCREAMING_SNAKE_CASE :      int       =   3 * [inputs["""prompt"""]]

        # forward
        SCREAMING_SNAKE_CASE :      int       =   audioldm_pipe(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Tuple       =   output.audios[0]

        SCREAMING_SNAKE_CASE :      List[str]       =   self.get_dummy_inputs(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      int       =   3 * [inputs.pop("""prompt"""		)]

        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   []
        for p in [prompt, negative_prompt]:
              SCREAMING_SNAKE_CASE :      str       =   audioldm_pipe.tokenizer(
                  UpperCAmelCase__				,				padding="""max_length"""				,				max_length=audioldm_pipe.tokenizer.model_max_length				,				truncation=UpperCAmelCase__				,				return_tensors="""pt"""				,				)
              SCREAMING_SNAKE_CASE :      Tuple       =   text_inputs["""input_ids"""].to(UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      str       =   audioldm_pipe.text_encoder(
                  UpperCAmelCase__				,				)
              SCREAMING_SNAKE_CASE :      Dict       =   text_embeds.text_embeds
              # additional L_2 normalization over each hidden-state
              SCREAMING_SNAKE_CASE :      Union[str, Any]       =   F.normalize(UpperCAmelCase__				,				dim=-1		)

              embeds.append(UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      Tuple       =   embeds

        # forward
        SCREAMING_SNAKE_CASE :      Dict       =   audioldm_pipe(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   output.audios[0]

        assert np.abs(audio_a - audio_a		).max() < 1e-2


  def  _lowercase      (			self    : List[str]		)					->Union[str, Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Tuple       =   """cpu"""  # ensure determinism for the device-dependent torch.Generator
        SCREAMING_SNAKE_CASE :      Any       =   self.get_dummy_components()
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   PNDMScheduler(skip_prk_steps=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Dict       =   AudioLDMPipeline(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   audioldm_pipe.to(UpperCAmelCase__		)
        audioldm_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      List[str]       =   self.get_dummy_inputs(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   """egg cracking"""
        SCREAMING_SNAKE_CASE :      List[Any]       =   audioldm_pipe(**UpperCAmelCase__				,				negative_prompt=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   output.audios[0]

        assert audio.ndim == 1
        assert len(UpperCAmelCase__		) == 2_5_6

        SCREAMING_SNAKE_CASE :      Dict       =   audio[:1_0]
        SCREAMING_SNAKE_CASE :      Dict       =   np.array(
            [-0.00_51, 0.00_50, -0.00_60, 0.00_34, -0.00_26, 0.00_33, -0.00_27, 0.00_33, -0.00_28, 0.00_32]		)

        assert np.abs(audio_slice - expected_slice		).max() < 1e-2


  def  _lowercase      (			self    : Union[str, Any]		)					->str:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Dict       =   """cpu"""  # ensure determinism for the device-dependent torch.Generator
        SCREAMING_SNAKE_CASE :      List[Any]       =   self.get_dummy_components()
        SCREAMING_SNAKE_CASE :      List[str]       =   PNDMScheduler(skip_prk_steps=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      List[Any]       =   AudioLDMPipeline(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      List[Any]       =   audioldm_pipe.to(UpperCAmelCase__		)
        audioldm_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      Dict       =   """A hammer hitting a wooden surface"""

        # test num_waveforms_per_prompt=1 (default)
        SCREAMING_SNAKE_CASE :      Optional[int]       =   audioldm_pipe(UpperCAmelCase__				,				num_inference_steps=2		).audios

        assert audios.shape == (1, 2_5_6)

        # test num_waveforms_per_prompt=1 (default) for batch of prompts
        SCREAMING_SNAKE_CASE :      Any       =   2
        SCREAMING_SNAKE_CASE :      List[Any]       =   audioldm_pipe([prompt] * batch_size				,				num_inference_steps=2		).audios

        assert audios.shape == (batch_size, 2_5_6)

        # test num_waveforms_per_prompt for single prompt
        SCREAMING_SNAKE_CASE :      Optional[int]       =   2
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   audioldm_pipe(UpperCAmelCase__				,				num_inference_steps=2				,				num_waveforms_per_prompt=UpperCAmelCase__		).audios

        assert audios.shape == (num_waveforms_per_prompt, 2_5_6)

        # test num_waveforms_per_prompt for batch of prompts
        SCREAMING_SNAKE_CASE :      Optional[int]       =   2
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   audioldm_pipe(
            [prompt] * batch_size				,				num_inference_steps=2				,				num_waveforms_per_prompt=UpperCAmelCase__		).audios

        assert audios.shape == (batch_size * num_waveforms_per_prompt, 2_5_6)


  def  _lowercase      (			self    : Optional[Any]		)					->List[str]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   """cpu"""  # ensure determinism for the device-dependent torch.Generator
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   self.get_dummy_components()
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   AudioLDMPipeline(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   audioldm_pipe.to(UpperCAmelCase__		)
        audioldm_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      List[Any]       =   audioldm_pipe.vocoder.config.sampling_rate

        SCREAMING_SNAKE_CASE :      Any       =   self.get_dummy_inputs(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Dict       =   audioldm_pipe(audio_length_in_s=0.0_16				,				**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      int       =   output.audios[0]

        assert audio.ndim == 1
        assert len(UpperCAmelCase__		) / vocoder_sampling_rate == 0.0_16

        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   audioldm_pipe(audio_length_in_s=0.0_32				,				**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      str       =   output.audios[0]

        assert audio.ndim == 1
        assert len(UpperCAmelCase__		) / vocoder_sampling_rate == 0.0_32


  def  _lowercase      (			self    : Dict		)					->str:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Optional[Any]       =   self.get_dummy_components()
        SCREAMING_SNAKE_CASE :      List[str]       =   AudioLDMPipeline(**UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   audioldm_pipe.to(UpperCAmelCase__		)
        audioldm_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      Optional[Any]       =   ["""hey"""]

        SCREAMING_SNAKE_CASE :      int       =   audioldm_pipe(UpperCAmelCase__				,				num_inference_steps=1		)
        SCREAMING_SNAKE_CASE :      List[str]       =   output.audios.shape
        assert audio_shape == (1, 2_5_6)

        SCREAMING_SNAKE_CASE :      List[Any]       =   audioldm_pipe.vocoder.config
        config.model_in_dim *= 2
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   SpeechTaHifiGan(UpperCAmelCase__		).to(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      List[Any]       =   audioldm_pipe(UpperCAmelCase__				,				num_inference_steps=1		)
        SCREAMING_SNAKE_CASE :      Any       =   output.audios.shape
        # waveform shape is unchanged, we just have 2x the number of mel channels in the spectrogram
        assert audio_shape == (1, 2_5_6)


  def  _lowercase      (			self    : List[Any]		)					->Union[str, Any]:
        """simple docstring"""







        self._test_attention_slicing_forward_pass(test_mean_pixel_difference=UpperCAmelCase__		)


  def  _lowercase      (			self    : Union[str, Any]		)					->List[str]:
        """simple docstring"""







        self._test_inference_batch_single_identical(test_mean_pixel_difference=UpperCAmelCase__		)




  @unittest.skipIf(
      torch_device != """cuda""" or not is_xformers_available()				,				reason="""XFormers attention is only available with CUDA and `xformers` installed"""				,				)
  def  _lowercase      (			self    : Tuple		)					->Optional[Any]:
        """simple docstring"""







        self._test_xformers_attention_forwardGenerator_pass(test_mean_pixel_difference=UpperCAmelCase__		)







@slow
class        a__       (   unittest.TestCase       ):







  """simple docstring"""




  def  _lowercase      (			self    : Tuple		)					->Union[str, Any]:
        """simple docstring"""







        super().tearDown()
        gc.collect()
        torch.cuda.empty_cache()


  def  _lowercase      (			self    : Optional[Any]				,				UpperCAmelCase__    : Dict				,				UpperCAmelCase__    : Optional[int]="cpu"				,				UpperCAmelCase__    : Optional[int]=torch.floataa				,				UpperCAmelCase__    : Optional[int]=0		)					->List[str]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   torch.Generator(device=UpperCAmelCase__		).manual_seed(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      List[str]       =   np.random.RandomState(UpperCAmelCase__		).standard_normal((1, 8, 1_2_8, 1_6)		)
        SCREAMING_SNAKE_CASE :      Dict       =   torch.from_numpy(UpperCAmelCase__		).to(device=UpperCAmelCase__				,				dtype=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      List[str]       =   {
            """prompt""": """A hammer hitting a wooden surface""",
            """latents""": latents,
            """generator""": generator,
            """num_inference_steps""": 3,
            """guidance_scale""": 2.5,
        }
        return inputs


  def  _lowercase      (			self    : int		)					->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      List[str]       =   AudioLDMPipeline.from_pretrained("""cvssp/audioldm"""		)
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   audioldm_pipe.to(UpperCAmelCase__		)
        audioldm_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      int       =   self.get_inputs(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Optional[int]       =   2_5
        SCREAMING_SNAKE_CASE :      int       =   audioldm_pipe(**UpperCAmelCase__		).audios[0]

        assert audio.ndim == 1
        assert len(UpperCAmelCase__		) == 8_1_9_2_0

        SCREAMING_SNAKE_CASE :      Dict       =   audio[7_7_2_3_0:7_7_2_4_0]
        SCREAMING_SNAKE_CASE :      List[Any]       =   np.array(
            [-0.48_84, -0.46_07, 0.00_23, 0.50_07, 0.58_96, 0.51_51, 0.38_13, -0.02_08, -0.36_87, -0.43_15]		)
        SCREAMING_SNAKE_CASE :      List[str]       =   np.abs(expected_slice - audio_slice		).max()
        assert max_diff < 1e-2




  def  _lowercase      (			self    : int		)					->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      int       =   AudioLDMPipeline.from_pretrained("""cvssp/audioldm"""		)
        SCREAMING_SNAKE_CASE :      Any       =   LMSDiscreteScheduler.from_config(audioldm_pipe.scheduler.config		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   audioldm_pipe.to(UpperCAmelCase__		)
        audioldm_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      str       =   self.get_inputs(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Optional[int]       =   audioldm_pipe(**UpperCAmelCase__		).audios[0]

        assert audio.ndim == 1
        assert len(UpperCAmelCase__		) == 8_1_9_2_0

        SCREAMING_SNAKE_CASE :      List[str]       =   audio[2_7_7_8_0:2_7_7_9_0]
        SCREAMING_SNAKE_CASE :      Any       =   np.array([-0.21_31, -0.08_73, -0.01_24, -0.01_89, 0.05_69, 0.13_73, 0.18_83, 0.28_86, 0.32_97, 0.22_12]		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   np.abs(expected_slice - audio_slice		).max()
        assert max_diff < 3e-2







from __future__ import annotations






def 					__lowercase      (     _A						,    _A			)     ->						list[str]:
      if nth_term == "":
            return [""]
      SCREAMING_SNAKE_CASE :      Optional[Any]       =   int(_A			)
      SCREAMING_SNAKE_CASE :      Optional[int]       =   int(_A			)
      SCREAMING_SNAKE_CASE :      list[str]       =   []
      for temp in range(int(_A			)			):
            series.append(F"1 / {pow(temp + 1						,    int(_A			)			)}" if series else """1"""			)
      return series


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  UpperCAmelCase__ :     Dict				    =    int(input("""Enter the last number (nth term) of the P-Series"""))
  UpperCAmelCase__ :     Optional[int]				    =    int(input("""Enter the power for  P-Series"""))
  print("""Formula of P-Series => 1+1/2^p+1/3^p ..... 1/n^p""")
  print(p_series(nth_term, power))




