hetpatel-tenup/image-processor
0
1from PIL import Image, ImageOps2 3class SimpleGrayScaleModel:4 """5 A simple model that uses PIL's ImageOps to convert an image to grayscale.6 This is designed for educational purposes and easy integration into the Gradio app.7 """8 9 def __init__(self):10 pass11 12 def predict(self, input_image: Image.Image) -> Image.Image:13 """14 Converts the input image to grayscale.15 16 Args:17 input_image (Image.Image): A PIL Image in RGB format.18 19 Returns:20 Image.Image: A grayscale PIL Image.21 """22 return ImageOps.grayscale(input_image)23 24 25def load_model():26 """27 Function to load and return the model.28 """29 return SimpleGrayScaleModel()30 31 32if __name__ == "__main__":33 # For testing purposes34 model = load_model()35 36 # Load a test image (Replace 'test.jpg' with an actual image file for testing)37 try:38 input_image = Image.open("test.jpg").convert("RGB")39 output_image = model.predict(input_image)40 41 # Show the input and output images42 input_image.show(title="Input Image")43 output_image.show(title="Grayscale Image")44 except FileNotFoundError:45 print("Please provide a valid 'test.jpg' image in the current directory.")46 