Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Function to create a list of cars with their images
|
| 5 |
+
def create_car_list(image_folder):
|
| 6 |
+
car_list = []
|
| 7 |
+
for image_name in os.listdir(image_folder):
|
| 8 |
+
if image_name.endswith(('.png', '.jpg', '.jpeg')):
|
| 9 |
+
car_name = os.path.splitext(image_name)[0] # Extract the car name from the image file name
|
| 10 |
+
image_path = os.path.join(image_folder, image_name)
|
| 11 |
+
car_image = Image.open(image_path)
|
| 12 |
+
|
| 13 |
+
car_list.append({
|
| 14 |
+
'name': car_name,
|
| 15 |
+
'image': car_image
|
| 16 |
+
})
|
| 17 |
+
|
| 18 |
+
return car_list
|
| 19 |
+
|
| 20 |
+
# Example usage
|
| 21 |
+
image_folder = 'path/to/your/car/images'
|
| 22 |
+
car_list = create_car_list(image_folder)
|
| 23 |
+
|
| 24 |
+
# Displaying the cars' names and showing their images
|
| 25 |
+
for car in car_list:
|
| 26 |
+
print(f"Car Name: {car['name']}")
|
| 27 |
+
car['image'].show()
|