awacke1 commited on
Commit
b1ad51c
โ€ข
1 Parent(s): 63c49e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
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 random images from directory
11
- images = os.listdir(image_dir)
 
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 = '.' # Set your directory path with images
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