

"""simple docstring"""





from typing import TYPE_CHECKING

from ..models.auto import AutoModelForVisionaSeq
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
   from PIL import Image




class  _lowerCAmelCase  (     lowercase       ):







 """simple docstring"""







 __UpperCAmelCase     : str       		=     "Salesforce/blip-image-captioning-base"
 __UpperCAmelCase     : Any       		=     (
     "This is a tool that generates a description of an image. It takes an input named `image` which should be the "
     "image to caption, and returns a text that contains the description in English."
 )
 __UpperCAmelCase     : Any       		=     "image_captioner"
 __UpperCAmelCase     : Optional[Any]       		=     AutoModelForVisionaSeq

 __UpperCAmelCase     : Tuple       		=     ["image"]
 __UpperCAmelCase     : int       		=     ["text"]


 def __init__(      self							:      Tuple, *UpperCAmelCase__							:      Optional[int], **UpperCAmelCase__							:      Dict     ):
    requires_backends(self, ["vision"]     )
    super().__init__(*UpperCAmelCase__, **UpperCAmelCase__     )


 def  _lowercase			(      self							:      str, UpperCAmelCase__							:      "Image"     ):
    return self.pre_processor(images=UpperCAmelCase__, return_tensors="pt"     )


 def  _lowercase			(      self							:      str, UpperCAmelCase__							:      Optional[int]     ):
    return self.model.generate(**UpperCAmelCase__     )



 def  _lowercase			(      self							:      Dict, UpperCAmelCase__							:      List[Any]     ):
    return self.pre_processor.batch_decode(UpperCAmelCase__, skip_special_tokens=UpperCAmelCase__     )[0].strip()


"""simple docstring"""





import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812




def   _A  (  )     ->						None:
   '''simple docstring'''


   print("Making key files...")
   make_key_files("rsa",      1024)
   print("Key files generation successful.")




def   _A  (  UpperCamelCase_					:	int)     ->						tuple[tuple[int, int], tuple[int, int]]:
   '''simple docstring'''


   print("Generating prime p...")
   __lowercase								=						rabinMiller.generate_large_prime(UpperCamelCase_)
   print("Generating prime q...")
   __lowercase								=						rabinMiller.generate_large_prime(UpperCamelCase_)
   __lowercase								=						p * q

   print("Generating e that is relatively prime to (p - 1) * (q - 1)...")
   while True:
      __lowercase								=						random.randrange(2 ** (key_size - 1),      2 ** (key_size))
      if cryptoMath.gcd(UpperCamelCase_,      (p - 1) * (q - 1)) == 1:
         break

   print("Calculating d that is mod inverse of e...")
   __lowercase								=						cryptoMath.find_mod_inverse(UpperCamelCase_,      (p - 1) * (q - 1))

   __lowercase								=						(n, e)
   __lowercase								=						(n, d)
   return (public_key, private_key)




def   _A  (  UpperCamelCase_					:	str,      UpperCamelCase_					:	int)     ->						None:
   '''simple docstring'''


   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()

   __lowercase		,__lowercase								=						generate_key(UpperCamelCase_)
   print(F"""\nWriting public key to file {name}_pubkey.txt...""")
   with open(F"""{name}_pubkey.txt""",      "w") as out_file:
      out_file.write(F"""{key_size},{public_key[0]},{public_key[1]}""")

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


if __name__ == "__main__":
   main()




