aiinference222 / test_it.py
mustava1259
m
72dddd7
raw
history blame
No virus
1.92 kB
from main import get_nude
import os
from PIL import Image
def create_grid_image(original, edited1, edited2):
# Create a new image with appropriate size to hold the three images (original, edited1, edited2)
width, height = original.size
grid = Image.new('RGB', (width, height * 3))
# Paste the original and edited images into the grid
grid.paste(original, (0, 0))
grid.paste(edited1, (0, height))
grid.paste(edited2, (0, height * 2))
return grid
def process_images(input_dir, output_dir, edit_function):
# Create the output directory if it doesn't exist
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Loop through all files in the input directory
for filename in os.listdir(input_dir):
print(f"Processing {filename}")
if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
base_filename, file_extension = os.path.splitext(filename)
grid_filename = f"{base_filename}1{file_extension}"
if os.path.exists(os.path.join(output_dir, grid_filename)):
print(f"Skipping {filename}, already exists in output directory")
continue
# Construct full file path
file_path = os.path.join(input_dir, filename)
# Process the image
original = Image.open(file_path)
try:
edited_images = edit_function(original)
except Exception as e:
print(f"Error processing {filename}: {e}")
continue
# Create the grid image
grid_image = create_grid_image(original, edited_images[0], edited_images[1])
# Save the grid image
grid_image.save(os.path.join(output_dir, grid_filename))
print(f"Saved {grid_filename}")
process_images('./dataset', './dataset_result_grids', get_nude)