Spaces:
Running
Running

Initial commit of the Computer Vision Journey presentation, including main application files, project pages, assets, and configuration. Added .gitignore to exclude unnecessary files and created requirements.txt for dependencies.
27818c1
unverified
""" | |
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"] | |