Spaces:
Sleeping
Sleeping
| """File to preprocess images""" | |
| import os | |
| from PIL import Image | |
| def get_images(folder: str) -> list: | |
| """Get images from a folder | |
| Args: | |
| folder (str): path to the folder | |
| Returns: | |
| images: list of images in the folder | |
| """ | |
| images = [] | |
| extetntions = [".png", ".jpeg", ".jpg"] | |
| for filename in os.listdir(folder): | |
| if any(filename.endswith(ext) for ext in extetntions): | |
| images.append(os.path.join(folder, filename)) | |
| return images | |
| def resize_image(img_path: str, target_w: int = 200, target_h: int = 200) -> Image.Image: | |
| """Resize an image | |
| Args: | |
| img_path (str): path to the image | |
| target_w (int): int to resize the width of the image | |
| target_h (int): int to resize the height of the image | |
| Returns: | |
| img: resized images | |
| """ | |
| img = Image.open(img_path) | |
| img = img.resize((target_w, target_h)) | |
| return img | |
| def get_image_caption(image_path): | |
| """Get the caption of an image | |
| Args: | |
| image_path (str): path to the image | |
| Returns: | |
| image_path: caption of the image | |
| """ | |
| image_path = image_path.split("/")[-1] | |
| image_path = image_path.split(".")[0] | |
| return image_path | |