|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.set_page_config() |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
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") |
|
img = img.resize(target_size) |
|
images_dict[filename] = img |
|
except Exception as e: |
|
st.error(f"Error loading images: {e}") |
|
return images_dict |
|
|
|
|
|
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: |
|
|
|
images = load_images_from_folder(folder_path, target_size=(300, 400)) |
|
|
|
if images: |
|
|
|
|
|
cols_per_row = 3 |
|
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) |
|
|
|
|
|
st.divider() |
|
else: |
|
st.warning("No images found in the specified folder.") |
|
else: |
|
st.info("Please enter a folder path to load and display images.") |
|
|
|
|
|
|
|
|