Spaces:
Sleeping
Sleeping
File size: 2,397 Bytes
27818c1 |
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 |
"""
Helper functions for the Computer Vision Journey presentation.
"""
import os
import streamlit as st
def check_asset_exists(filename):
"""
Check if an asset file exists and return the path if it does, otherwise return None.
Args:
filename (str): The filename to check in the assets directory
Returns:
str or None: The full path to the asset if it exists, None otherwise
"""
assets_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "assets")
filepath = os.path.join(assets_dir, filename)
if os.path.exists(filepath):
return filepath
else:
return None
def display_asset_or_placeholder(
filename, asset_type="image", caption=None, use_column_width=True
):
"""
Display an asset or a placeholder if the asset doesn't exist.
Args:
filename (str): The filename of the asset
asset_type (str): The type of asset ('image' or 'video')
caption (str, optional): Caption for the asset
use_column_width (bool, optional): Whether to use the full column width
"""
filepath = check_asset_exists(filename)
if filepath:
if asset_type == "image":
st.image(filepath, caption=caption, use_container_width=use_column_width)
elif asset_type == "video":
st.video(filepath)
else:
if asset_type == "image":
st.warning(
f"Place '{filename}' in the assets directory to display the {caption or 'image'}"
)
elif asset_type == "video":
st.warning(
f"Place '{filename}' in the assets directory to display the {caption or 'video'}"
)
def display_iframe_or_link(url, height=500):
"""
Display an iframe to an external URL or a link if iframe loading fails.
Args:
url (str): The URL to embed
height (int, optional): Height of the iframe
"""
try:
st.components.v1.iframe(url, height=height)
except Exception:
st.warning(f"Unable to load iframe. Please visit the link directly: {url}")
st.markdown(f"[Open in new tab]({url})")
def get_project_tabs():
"""
Return a list of project tab names for consistent naming across pages.
Returns:
list: List of project tab names
"""
return ["Black Bee Drones", "Asimov Foundation", "CafeDL", "Tech4Humans"]
|