Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,14 +2,20 @@ import streamlit as st
|
|
2 |
import os
|
3 |
import random
|
4 |
|
5 |
-
# ๐ผ๏ธ 1. Display two columns, each with a random image from the directory
|
6 |
def display_images(image_dir):
|
7 |
-
"""๐ผ๏ธ Function 1: Displays two random images side by side for voting."""
|
|
|
8 |
col1, col2 = st.columns(2)
|
9 |
|
10 |
-
# ๐๏ธ Load
|
11 |
-
|
|
|
12 |
|
|
|
|
|
|
|
|
|
13 |
# ๐ธ Randomly select two images
|
14 |
image1 = random.choice(images)
|
15 |
image2 = random.choice(images)
|
@@ -57,7 +63,7 @@ def main():
|
|
57 |
show_vote_history()
|
58 |
|
59 |
# ๐ผ๏ธ Display images for voting
|
60 |
-
image_dir = '.' #
|
61 |
display_images(image_dir)
|
62 |
|
63 |
# ๐ 5. Run the app
|
|
|
2 |
import os
|
3 |
import random
|
4 |
|
5 |
+
# ๐ผ๏ธ 1. Display two columns, each with a random image from the current directory
|
6 |
def display_images(image_dir):
|
7 |
+
"""๐ผ๏ธ Function 1: Displays two random images side by side for voting, filtered to only show image files."""
|
8 |
+
|
9 |
col1, col2 = st.columns(2)
|
10 |
|
11 |
+
# ๐๏ธ Load and filter only image files from the directory
|
12 |
+
valid_extensions = ('.png', '.jpg', '.jpeg', '.gif', '.bmp', '.tiff', '.webp') # Common image file types
|
13 |
+
images = [f for f in os.listdir(image_dir) if f.lower().endswith(valid_extensions)]
|
14 |
|
15 |
+
if len(images) < 2:
|
16 |
+
st.error("Not enough images in the directory.")
|
17 |
+
return
|
18 |
+
|
19 |
# ๐ธ Randomly select two images
|
20 |
image1 = random.choice(images)
|
21 |
image2 = random.choice(images)
|
|
|
63 |
show_vote_history()
|
64 |
|
65 |
# ๐ผ๏ธ Display images for voting
|
66 |
+
image_dir = '.' # Current directory where the app is running
|
67 |
display_images(image_dir)
|
68 |
|
69 |
# ๐ 5. Run the app
|