File size: 3,981 Bytes
23b7e72 |
1 2 3 4 5 6 7 8 9 10 11 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
import streamlit as st
import pandas as pd
import os
import base64
from pathlib import Path
import streamlit as st
import os
from PIL import Image
# path = os.path.dirname(__file__)
# file_ = open(f"{path}/logo.png", "rb")
# contents = file_.read()
# data_url = base64.b64encode(contents).decode("utf-8")
# file_.close()
# def load_local_css(file_name):
# with open(file_name) as f:
# st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
# def set_header():
# return st.markdown(
# f"""<div class='main-header'>
# <h1>Synthetic Control</h1>
# <img src="data:image;base64,{data_url}", alt="Logo">
# </div>""",
# unsafe_allow_html=True,
# )
st.set_page_config()
# load_local_css("styles.css")
# set_header()
st.title("The Art of Words: Vachana's Collection")
def load_images_from_folder(folder_path):
"""
Load all images from the specified folder and store them in a dictionary.
Args:
folder_path (str): Path to the folder containing images.
Returns:
dict: A dictionary with image filenames as keys and PIL Image objects as values.
"""
images_dict = {}
try:
for filename in os.listdir(folder_path):
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
img_path = os.path.join(folder_path, filename)
images_dict[filename] = Image.open(img_path)
except Exception as e:
st.error(f"Error loading images: {e}")
return images_dict
# Folder selection
with st.expander("Click to Discover the Masterpiece"):
folder_path = 'Photos'
def load_images_from_folder(folder_path, target_size=(200, 200)):
"""
Load all images from the specified folder, resize them to a uniform size, and store them in a dictionary.
Args:
folder_path (str): Path to the folder containing images.
target_size (tuple): Desired size for all images (width, height).
Returns:
dict: A dictionary with image filenames as keys and resized PIL Image objects as values.
"""
images_dict = {}
try:
for filename in os.listdir(folder_path):
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
img_path = os.path.join(folder_path, filename)
img = Image.open(img_path).convert("RGB") # Convert to RGB for consistency
img = img.resize(target_size) # Resize image
images_dict[filename] = img
except Exception as e:
st.error(f"Error loading images: {e}")
return images_dict
# Streamlit UI
if folder_path:
if not os.path.exists(folder_path):
st.error("The specified folder path does not exist. Please enter a valid path.")
else:
# Load images
images = load_images_from_folder(folder_path, target_size=(300, 400)) # Set desired size
if images:
# Display images side by side with a row break
cols_per_row = 3 # Adjust the number of images displayed per row
images_list = list(images.items())
for i in range(0, len(images_list), cols_per_row):
cols = st.columns(cols_per_row)
for col, (img_name, img) in zip(cols, images_list[i:i + cols_per_row]):
with col:
st.image(img, use_container_width=True)
# Add a break after each row
st.divider() # Simple divider
else:
st.warning("No images found in the specified folder.")
else:
st.info("Please enter a folder path to load and display images.")
|