Spaces:
Build error
Build error
added
Browse files- app.py +55 -38
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,39 +1,56 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
if
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Title of the app
|
| 6 |
+
st.title("Logo Voter App")
|
| 7 |
+
|
| 8 |
+
# Path to the images folder
|
| 9 |
+
images_folder = "images"
|
| 10 |
+
|
| 11 |
+
# Check if the images folder exists
|
| 12 |
+
if not os.path.exists(images_folder):
|
| 13 |
+
st.error("The 'images' folder is missing!")
|
| 14 |
+
st.stop()
|
| 15 |
+
|
| 16 |
+
# Get a list of all image files in the folder
|
| 17 |
+
image_files = [f for f in os.listdir(images_folder) if f.endswith(('png', 'jpg', 'jpeg'))]
|
| 18 |
+
|
| 19 |
+
# If no images found, show a message
|
| 20 |
+
if not image_files:
|
| 21 |
+
st.error("No images found in the 'images' folder.")
|
| 22 |
+
st.stop()
|
| 23 |
+
|
| 24 |
+
# Display images in a grid layout
|
| 25 |
+
st.write("Uploaded Images:")
|
| 26 |
+
|
| 27 |
+
# Define the number of columns for the grid
|
| 28 |
+
columns = st.columns(3) # 3 columns for layout
|
| 29 |
+
|
| 30 |
+
# Initialize a dictionary to store votes for each image
|
| 31 |
+
votes = {image_file: 0 for image_file in image_files}
|
| 32 |
+
|
| 33 |
+
# Loop through the images and display them in the columns
|
| 34 |
+
for idx, image_file in enumerate(image_files):
|
| 35 |
+
with columns[idx % 3]: # Loop through columns
|
| 36 |
+
# Open the image
|
| 37 |
+
img_path = os.path.join(images_folder, image_file)
|
| 38 |
+
img = Image.open(img_path)
|
| 39 |
+
|
| 40 |
+
# Display the image
|
| 41 |
+
st.image(img, use_column_width=True, caption=image_file)
|
| 42 |
+
|
| 43 |
+
# Voting buttons
|
| 44 |
+
col1, col2 = st.columns([1, 1])
|
| 45 |
+
with col1:
|
| 46 |
+
if st.button(f"Like {image_file}", key=f"like_{idx}"):
|
| 47 |
+
votes[image_file] += 1
|
| 48 |
+
with col2:
|
| 49 |
+
if st.button(f"Dislike {image_file}", key=f"dislike_{idx}"):
|
| 50 |
+
votes[image_file] -= 1
|
| 51 |
+
|
| 52 |
+
# Show voting results
|
| 53 |
+
st.write("### Voting Results:")
|
| 54 |
+
for image_file, vote_count in votes.items():
|
| 55 |
+
st.write(f"**{image_file}:** {vote_count} votes")
|
| 56 |
+
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
streamlit
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pillow
|