





"""simple docstring"""





from PIL import Image


def      UpperCAmelCase__				(    SCREAMING_SNAKE_CASE	:		Image				,		SCREAMING_SNAKE_CASE	:		float     ):







      '''simple docstring'''




      def brightness(SCREAMING_SNAKE_CASE	:		int     ) -> float:
            return 1_28 + level + (c - 1_28)

      if not -2_55.0 <= level <= 2_55.0:
            raise ValueError("""level must be between -255.0 (black) and 255.0 (white)"""     )
      return img.point(SCREAMING_SNAKE_CASE     )


if __name__ == "__main__":
       # Load image
       with Image.open("image_data/lena.jpg") as img:
              # Change brightness to 100
              SCREAMING_SNAKE_CASE__   =  change_brightness(img, 100)
              brigt_img.save("image_data/lena_brightness.png", format="png")













"""simple docstring"""





import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
       import torch

       from transformers import AutoModelForImageClassification

if is_vision_available():
       from transformers import AutoImageProcessor

@require_torch
@require_vision
class 						lowercase   (   unittest.TestCase   ):





      @slow
      def        _snake_case     (			self					)						->	Any:
            lowerCAmelCase    		=			AutoImageProcessor.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""					)
            lowerCAmelCase    		=			AutoModelForImageClassification.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""					)
            model.to(lowercase					)

            from datasets import load_dataset

            lowerCAmelCase    		=			load_dataset("""nielsr/rvlcdip-demo"""					)

            lowerCAmelCase    		=			dataset["""train"""][0]["""image"""].convert("""RGB"""					)

            lowerCAmelCase    		=			image_processor(lowercase ,		return_tensors="""pt"""					).to(lowercase					)

            # forward pass
            with torch.no_grad():
                  lowerCAmelCase    		=			model(**lowercase					)
                  lowerCAmelCase    		=			outputs.logits

            lowerCAmelCase    		=			torch.Size((1, 16)					)
            self.assertEqual(logits.shape ,		lowercase					)

            lowerCAmelCase    		=			torch.tensor(
                [-0.4_158, -0.4_092, -0.4_347] ,		device=lowercase ,		dtype=torch.float ,		)
            self.assertTrue(torch.allclose(logits[0, :3] ,		lowercase ,		atol=1e-4					)					)






