Update app.py
Browse files
app.py
CHANGED
|
@@ -6,28 +6,30 @@ from PIL import Image
|
|
| 6 |
|
| 7 |
# Step 1: Download the latest version of the dataset and get the path
|
| 8 |
path = kagglehub.dataset_download("imreallyjohn/cartoonset10k")
|
| 9 |
-
images_folder = "/home/user/.cache/kagglehub/datasets/imreallyjohn/cartoonset10k/versions/1"
|
| 10 |
-
|
| 11 |
# Display the dataset path
|
| 12 |
st.write("Path to dataset files:", images_folder)
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
else:
|
| 31 |
-
st.error("No available images to display.")
|
| 32 |
-
except Exception as e:
|
| 33 |
-
st.error(f"Error accessing images: {e}")
|
|
|
|
| 6 |
|
| 7 |
# Step 1: Download the latest version of the dataset and get the path
|
| 8 |
path = kagglehub.dataset_download("imreallyjohn/cartoonset10k")
|
| 9 |
+
images_folder = "/home/user/.cache/kagglehub/datasets/imreallyjohn/cartoonset10k/versions/1"
|
|
|
|
| 10 |
# Display the dataset path
|
| 11 |
st.write("Path to dataset files:", images_folder)
|
| 12 |
|
| 13 |
+
# Step 2: List all image files in the dataset directory
|
| 14 |
+
try:
|
| 15 |
+
image_files = [f for f in os.listdir(images_folder) if f.endswith('.png')] # List .png files
|
| 16 |
+
num_images = len(image_files)
|
| 17 |
+
|
| 18 |
+
# Display the number of images loaded
|
| 19 |
+
st.write(f"Total images loaded: {num_images}")
|
| 20 |
+
|
| 21 |
+
if num_images == 0:
|
| 22 |
+
st.error("No available images to display. Please check the folder path and contents.")
|
| 23 |
+
except Exception as e:
|
| 24 |
+
st.error(f"Error accessing images: {e}")
|
| 25 |
|
| 26 |
+
# Button to generate a random avatar if images are available
|
| 27 |
+
if num_images > 0 and st.button("Generate Random Avatar"):
|
| 28 |
+
# Step 3: Select a random available image
|
| 29 |
+
random_image_filename = random.choice(image_files)
|
| 30 |
+
image_path = os.path.join(images_folder, random_image_filename)
|
| 31 |
+
|
| 32 |
+
# Load and display the selected image
|
| 33 |
+
selected_image = Image.open(image_path)
|
| 34 |
+
st.image(selected_image, caption=f"Displayed image: {random_image_filename}")
|
| 35 |
+
st.write(f"Displayed image: {random_image_filename}")
|
|
|
|
|
|
|
|
|
|
|
|