newpro / app.py
Lubna25's picture
Create app.py
328aad1 verified
raw
history blame contribute delete
851 Bytes
from PIL import Image
import os
# Function to create a list of cars with their images
def create_car_list(image_folder):
car_list = []
for image_name in os.listdir(image_folder):
if image_name.endswith(('.png', '.jpg', '.jpeg')):
car_name = os.path.splitext(image_name)[0] # Extract the car name from the image file name
image_path = os.path.join(image_folder, image_name)
car_image = Image.open(image_path)
car_list.append({
'name': car_name,
'image': car_image
})
return car_list
# Example usage
image_folder = 'path/to/your/car/images'
car_list = create_car_list(image_folder)
# Displaying the cars' names and showing their images
for car in car_list:
print(f"Car Name: {car['name']}")
car['image'].show()