



import math
import os

import cva
import numpy as np

UpperCamelCase_	       =   2_55.0







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase	)       ->       float:



						'''simple docstring'''






						UpperCAmelCase_     							=     np.mean((original - contrast) ** 2	)
						if mse == 0:
												return 100

						return 20 * math.logaa(PIXEL_MAX / math.sqrt(__UpperCAmelCase	)	)







def 				A			(		)       ->       None:



						'''simple docstring'''






						UpperCAmelCase_     							=     os.path.dirname(os.path.realpath(__UpperCAmelCase	)	)
						# Loading images (original image and compressed image)
						UpperCAmelCase_     							=     cva.imread(os.path.join(__UpperCAmelCase							,					'''image_data/original_image.png'''	)	)
						UpperCAmelCase_     							=     cva.imread(os.path.join(__UpperCAmelCase							,					'''image_data/compressed_image.png'''	)							,					1	)

						UpperCAmelCase_     							=     cva.imread(os.path.join(__UpperCAmelCase							,					'''image_data/PSNR-example-base.png'''	)	)
						UpperCAmelCase_     							=     cva.imread(
						    os.path.join(__UpperCAmelCase							,					'''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(__UpperCAmelCase							,					__UpperCAmelCase	)} dB"	)

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


if __name__ == "__main__":
							main()










import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
							from PIL import Image







class 							a_  (		unittest.TestCase					, _snake_case				):

						def 	__a       (    self	:Union[str, Any])		->					Optional[Any]:
												UpperCAmelCase_     							=     load_tool('''image-question-answering''')
												self.tool.setup()
												UpperCAmelCase_     							=     load_tool('''image-question-answering'''   ,						remote=_lowercase)

						def 	__a       (    self	:int)		->					Union[str, Any]:
												UpperCAmelCase_     							=     Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO''')) / '''000000039769.png''')
												UpperCAmelCase_     							=     self.tool(_lowercase   ,						'''How many cats are sleeping on the couch?''')
												self.assertEqual(_lowercase   ,						'''2''')

						def 	__a       (    self	:int)		->					Dict:
												UpperCAmelCase_     							=     Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO''')) / '''000000039769.png''')
												UpperCAmelCase_     							=     self.remote_tool(_lowercase   ,						'''How many cats are sleeping on the couch?''')
												self.assertEqual(_lowercase   ,						'''2''')

						def 	__a       (    self	:Optional[int])		->					int:
												UpperCAmelCase_     							=     Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO''')) / '''000000039769.png''')
												UpperCAmelCase_     							=     self.tool(image=_lowercase   ,						question='''How many cats are sleeping on the couch?''')
												self.assertEqual(_lowercase   ,						'''2''')




						def 	__a       (    self	:Optional[Any])		->					List[str]:
												UpperCAmelCase_     							=     Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO''')) / '''000000039769.png''')
												UpperCAmelCase_     							=     self.remote_tool(image=_lowercase   ,						question='''How many cats are sleeping on the couch?''')
												self.assertEqual(_lowercase   ,						'''2''')





