Update app.py
Browse files
app.py
CHANGED
|
@@ -36,32 +36,27 @@ tokenizer = AutoTokenizer.from_pretrained(
|
|
| 36 |
)
|
| 37 |
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
"""
|
| 43 |
-
# Convert input to a PIL Image (if it isn’t already)
|
| 44 |
-
image = Image.fromarray(np.array(image))
|
| 45 |
-
|
| 46 |
-
# Apply enhancement filters
|
| 47 |
-
image = ImageEnhance.Sharpness(image).enhance(2.0) # Increase sharpness
|
| 48 |
-
image = ImageEnhance.Contrast(image).enhance(1.5) # Increase contrast
|
| 49 |
-
image = ImageEnhance.Brightness(image).enhance(0.8) # Reduce brightness
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
-
padded_image.paste(image, (pad_x // 2, pad_y // 2))
|
| 63 |
|
| 64 |
-
return padded_image
|
| 65 |
|
| 66 |
|
| 67 |
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
|
| 39 |
+
from PIL import Image, ImageEnhance
|
| 40 |
+
import numpy as np
|
| 41 |
+
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
def preprocessing(image):
|
| 44 |
+
"""Apply three enhancement filters without resizing or cropping."""
|
| 45 |
+
|
| 46 |
+
# Ensure the image is a PIL Image
|
| 47 |
+
if not isinstance(image, Image.Image):
|
| 48 |
+
image = Image.fromarray(np.array(image))
|
| 49 |
|
| 50 |
+
# Apply enhancements
|
| 51 |
+
image = ImageEnhance.Sharpness(image).enhance(2.0) # Increase sharpness
|
| 52 |
+
image = ImageEnhance.Contrast(image).enhance(1.5) # Increase contrast
|
| 53 |
+
image = ImageEnhance.Brightness(image).enhance(0.8) # Reduce brightness
|
| 54 |
|
| 55 |
+
# Convert to tensor without resizing
|
| 56 |
+
image_tensor = torch.tensor(np.array(image)).permute(2, 0, 1).float() / 255.0 # Shape: [C, H, W]
|
| 57 |
|
| 58 |
+
return image_tensor
|
|
|
|
| 59 |
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
|