

# this script builds a small sample spm file tests/fixtures/test_sentencepiece_no_bos.model, with features needed by pegasus

# 1. pip install sentencepiece
#
# 2. wget https://raw.githubusercontent.com/google/sentencepiece/master/data/botchan.txt

# 3. build
import sentencepiece as spm

# pegasus:
# 1. no bos
# 2. eos_id is 1
# 3. unk_id is 2
# build a sample spm file accordingly
spm.SentencePieceTrainer.train(
    """--input=botchan.txt --model_prefix=test_sentencepiece_no_bos --bos_id=-1 --unk_id=2  --eos_id=1  --vocab_size=1000"""
)

# 4. now update the fixture
# mv test_sentencepiece_no_bos.model ../../tests/fixtures/





import math
import os

import cva
import numpy as np

__UpperCAmelCase      = 255.0





def 	snake_case_      (__A     :						float					,   __A     :						float     )			->	float:
   __lowerCAmelCase  :			Any					    =						np.mean((original - contrast) ** 2     )
   if mse == 0:
      return 1_0_0

   return 2_0 * math.logaa(PIXEL_MAX / math.sqrt(__A     )     )





def 	snake_case_      ()			->	None:
   __lowerCAmelCase  :			int					    =						os.path.dirname(os.path.realpath(__A     )     )
   # Loading images (original image and compressed image)
   __lowerCAmelCase  :			Tuple					    =						cva.imread(os.path.join(__A					,   """image_data/original_image.png"""     )     )
   __lowerCAmelCase  :			Dict					    =						cva.imread(os.path.join(__A					,   """image_data/compressed_image.png"""     )					,   1     )

   __lowerCAmelCase  :			Optional[int]					    =						cva.imread(os.path.join(__A					,   """image_data/PSNR-example-base.png"""     )     )
   __lowerCAmelCase  :			Optional[int]					    =						cva.imread(
       os.path.join(__A					,   """image_data/PSNR-example-comp-10.jpg"""     )					,   1     )

   # Value expected: 29.73dB
   print("""-- First Test --"""     )
   print(f'''PSNR value is {peak_signal_to_noise_ratio(__A					,   __A     )} dB'''     )

   # # Value expected: 31.53dB (Wikipedia Example)
   print("""\n-- Second Test --"""     )
   print(f'''PSNR value is {peak_signal_to_noise_ratio(__A					,   __A     )} dB'''     )


if __name__ == "__main__":
   main()


