File size: 955 Bytes
b04502d a632f88 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import kagglehub
import os
import random
from PIL import Image
# Step 1: Download the latest version of the dataset
path = kagglehub.dataset_download("imreallyjohn/cartoonset10k")
print("Path to dataset files:", path)
# Step 2: List all image files in the dataset directory
images_folder = os.path.join(path, "/content/CartoonAvatar/CartoonAvatar") # Adjust the subdirectory if needed
image_files = [f for f in os.listdir(images_folder) if f.endswith('.png')] # Filter for .png files
if image_files:
# Step 3: Select a random available image
random_image_filename = random.choice(image_files) # Select a random image
image_path = os.path.join(images_folder, random_image_filename)
# Step 4: Load and display the selected image
selected_image = Image.open(image_path)
selected_image.show()
print(f"Displayed image: {random_image_filename}")
display(selected_image)
else:
print("No available images to display.")
|