

'''simple docstring'''

import unittest

import numpy as np

from diffusers import OnnxStableDiffusionInpaintPipelineLegacy
from diffusers.utils.testing_utils import (
    is_onnx_available,
    load_image,
    load_numpy,
    nightly,
    require_onnxruntime,
    require_torch_gpu,
)


if is_onnx_available():
 import onnxruntime as ort




@nightly
@require_onnxruntime
@require_torch_gpu
class 	A_			(    unittest.TestCase							):






     '''simple docstring'''



     @property
     def        UpperCAmelCase_	(		self			:					Any	)						->     int:
      return (
          "CUDAExecutionProvider",
          {
              "gpu_mem_limit": "15000000000",  # 15GB
              "arena_extend_strategy": "kSameAsRequested",
          },
      )


     @property
     def        UpperCAmelCase_	(		self			:					List[Any]	)						->     List[Any]:
      UpperCAmelCase	:     Optional[int]						 =			ort.SessionOptions()
      UpperCAmelCase	:     Dict						 =			False
      return options




     def        UpperCAmelCase_	(		self			:					Optional[int]	)						->     Dict:
      UpperCAmelCase	:     Dict						 =			load_image(
          'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
          '/in_paint/overture-creations-5sI6fQgYIuo.png'	)
      UpperCAmelCase	:     Any						 =			load_image(
          'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
          '/in_paint/overture-creations-5sI6fQgYIuo_mask.png'	)
      UpperCAmelCase	:     List[Any]						 =			load_numpy(
          'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
          '/in_paint/red_cat_sitting_on_a_park_bench_onnx.npy'	)

      # using the PNDM scheduler by default
      UpperCAmelCase	:     Any						 =			OnnxStableDiffusionInpaintPipelineLegacy.from_pretrained(
          'CompVis/stable-diffusion-v1-4'					,      revision='onnx'					,      safety_checker=lowercase_					,      feature_extractor=lowercase_					,      provider=self.gpu_provider					,      sess_options=self.gpu_options					,      )
      pipe.set_progress_bar_config(disable=lowercase_	)

      UpperCAmelCase	:     List[str]						 =			'A red cat sitting on a park bench'

      UpperCAmelCase	:     List[str]						 =			np.random.RandomState(0	)
      UpperCAmelCase	:     Optional[Any]						 =			pipe(
          prompt=lowercase_					,      image=lowercase_					,      mask_image=lowercase_					,      strength=0.75					,      guidance_scale=7.5					,      num_inference_steps=15					,      generator=lowercase_					,      output_type='np'					,      )

      UpperCAmelCase	:     Any						 =			output.images[0]

      assert image.shape == (512, 512, 3)
      assert np.abs(expected_image - image	).max() < 1E-2







'''simple docstring'''

import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

lowercase__         =      3




def 				UpperCamelCase(					UpperCAmelCase_     ):
 print('Generating primitive root of p'     )
 while True:
  UpperCAmelCase	:     Union[str, Any]						 =			random.randrange(3  ,	UpperCAmelCase_     )
  if pow(UpperCAmelCase_  ,	2  ,	UpperCAmelCase_     ) == 1:
   continue
  if pow(UpperCAmelCase_  ,	UpperCAmelCase_  ,	UpperCAmelCase_     ) == 1:
   continue
  return g




def 				UpperCamelCase(					UpperCAmelCase_     ):
 print('Generating prime p...'     )
 UpperCAmelCase	:     str						 =			rabin_miller.generate_large_prime(UpperCAmelCase_     )  # select large prime number.
 UpperCAmelCase	:     List[str]						 =			primitive_root(UpperCAmelCase_     )  # one primitive root on modulo p.
 UpperCAmelCase	:     List[Any]						 =			random.randrange(3  ,	UpperCAmelCase_     )  # private_key -> have to be greater than 2 for safety.
 UpperCAmelCase	:     List[Any]						 =			cryptomath.find_mod_inverse(pow(UpperCAmelCase_  ,	UpperCAmelCase_  ,	UpperCAmelCase_     )  ,	UpperCAmelCase_     )

 UpperCAmelCase	:     Tuple						 =			(key_size, e_a, e_a, p)
 UpperCAmelCase	:     Optional[int]						 =			(key_size, d)

 return public_key, private_key




def 				UpperCamelCase(					UpperCAmelCase_  ,	UpperCAmelCase_     ):
 if os.path.exists(F"""{name}_pubkey.txt"""     ) or os.path.exists(F"""{name}_privkey.txt"""     ):
  print('\nWARNING:'     )
  print(
      F"""\"{name}_pubkey.txt\" or \"{name}_privkey.txt\" already exists. \n"""
      'Use a different name or delete these files and re-run this program.'     )
  sys.exit()

 UpperCAmelCase ,			UpperCAmelCase	:     Dict						 =			generate_key(UpperCAmelCase_     )
 print(F"""\nWriting public key to file {name}_pubkey.txt..."""     )
 with open(F"""{name}_pubkey.txt"""  ,	'w'     ) as fo:
  fo.write(F"""{public_key[0]},{public_key[1]},{public_key[2]},{public_key[3]}"""     )

 print(F"""Writing private key to file {name}_privkey.txt..."""     )
 with open(F"""{name}_privkey.txt"""  ,	'w'     ) as fo:
  fo.write(F"""{private_key[0]},{private_key[1]}"""     )




def 				UpperCamelCase(					):
 print('Making key files...'     )
 make_key_files('elgamal'  ,	20_48     )
 print('Key files generation successful'     )


if __name__ == "__main__":
 main()




