import streamlit as st import requests from PIL import Image as PILImage from io import BytesIO import re import pandas as pd import os from streamlit_autorefresh import st_autorefresh # Auto-refresh every 30 seconds (30,000 milliseconds) st_autorefresh(interval=30 * 1000, key="auto-refresh") # ------------------ UI and Styling ------------------ # Fullscreen mode and hide Streamlit elements (Menu, Footer) # ------------------ UI and Styling ------------------ # ------------------ UI and Styling ------------------ # ------------------ UI and Styling ------------------ # Fullscreen mode and hide Streamlit elements (Menu, Footer) st.markdown(""" """, unsafe_allow_html=True) # ------------------ Image Helpers ------------------ # Convert Google Drive URL to direct link def convert_drive_url(url): match = re.search(r'/d/([a-zA-Z0-9_-]+)|id=([a-zA-Z0-9_-]+)', url) file_id = match.group(1) if match and match.group(1) else match.group(2) if match else None if file_id: return f"https://drive.google.com/uc?export=view&id={file_id}" return None def prepare_image(img, size=(500, 500), bg_color=(17, 17, 17)): # Resize image keeping aspect ratio, then pad to desired size img.thumbnail(size, PILImage.Resampling.LANCZOS) background = PILImage.new('RGB', size, bg_color) offset = ((size[0] - img.width) // 2, (size[1] - img.height) // 2) background.paste(img, offset) return background # Download image from URL def download_image(url): try: response = requests.get(url) response.raise_for_status() return PILImage.open(BytesIO(response.content)).convert("RGB") except Exception as e: st.error(f"Failed to load image from {url}: {e}") return None import streamlit as st import pandas as pd import gspread from oauth2client.service_account import ServiceAccountCredentials ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Construct full path to app.json CONFIG_PATH = os.path.join(ROOT_DIR, "test_app_1.json") # Google Sheets Setup scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"] creds = ServiceAccountCredentials.from_json_keyfile_name("src/test_app_1.json", scope) client = gspread.authorize(creds) #https://docs.google.com/spreadsheets/d/1t96-Y21Nuj4dSy1UM4xJOnG3mlfF0C_vtfKRrptzKQ8/edit?usp=sharing # Access the sheet sheet = client.open_by_key("1t96-Y21Nuj4dSy1UM4xJOnG3mlfF0C_vtfKRrptzKQ8").sheet1 data = sheet.get_all_records() df = pd.DataFrame(data) # ------------------ App Layout ------------------ # App title #st.markdown("

", unsafe_allow_html=True) # Let user select number of columns (1 to 5) cols_count = 3 # Prepare images and captions rows_data = list(df.tail(3).itertuples(index=False)) # Exclude the index from tuple # Create columns for grid layout cols = st.columns(cols_count) # ------------------ Image Grid ------------------ for idx, row in enumerate(rows_data): col = cols[idx % cols_count] name = row.Name greeting = row.Greetings url = convert_drive_url(row.Picture) img = download_image(url) with col: # Image Display if img: uniform_img = prepare_image(img, size=(500, 500)) st.image(uniform_img, use_container_width=True) else: st.markdown('
No Image
', unsafe_allow_html=True) # Separator Line (between Image and Greeting) st.markdown('
', unsafe_allow_html=True) # Create the cloud-like container for both Name and Greeting below the image st.markdown(f"""

{name}

{greeting}

""", unsafe_allow_html=True)