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.")