A faster way to build and share data apps
Media display capabilities and status messaging functions for rich content presentation and user feedback. These components enable multimedia content display and effective user communication.
Display images, audio, video, and PDF content with various formatting options.
def image(image, caption=None, width=None, use_column_width=None, clamp=False, channels="RGB", output_format="auto", use_container_width=False):
"""
Display an image or list of images.
Parameters:
- image: Image data (PIL Image, numpy array, file path, URL, or bytes)
- caption (str or list): Image caption(s)
- width (int): Image width in pixels
- use_column_width (bool): Deprecated - use use_container_width instead
- clamp (bool): Clamp image pixel values to valid range
- channels (str): Color channel interpretation ('RGB' or 'BGR')
- output_format (str): Output format ('JPEG', 'PNG', or 'auto')
- use_container_width (bool): Use full container width
Returns:
None
"""
def audio(data, format="audio/wav", start_time=0, sample_rate=None, end_time=None, loop=False, autoplay=False):
"""
Display an audio player widget.
Parameters:
- data: Audio data (file path, URL, bytes, or numpy array)
- format (str): Audio format MIME type
- start_time (int): Start playback time in seconds
- sample_rate (int): Sample rate for numpy array data
- end_time (int): End playback time in seconds
- loop (bool): Loop audio playback
- autoplay (bool): Start playing automatically
Returns:
None
"""
def video(data, format="video/mp4", start_time=0, subtitles=None, end_time=None, loop=False, autoplay=False, muted=False):
"""
Display a video player widget.
Parameters:
- data: Video data (file path, URL, or bytes)
- format (str): Video format MIME type
- start_time (int): Start playback time in seconds
- subtitles (str or list): Subtitle file path(s) or WebVTT content
- end_time (int): End playback time in seconds
- loop (bool): Loop video playback
- autoplay (bool): Start playing automatically
- muted (bool): Start with audio muted
Returns:
None
"""
def pdf(data, width=None, height=600):
"""
Display a PDF viewer widget.
Parameters:
- data: PDF data (file path, URL, or bytes)
- width (int): Viewer width in pixels
- height (int): Viewer height in pixels
Returns:
None
"""Provide user feedback with different severity levels and styling.
def success(body, icon=True):
"""
Display a success message with green styling.
Parameters:
- body (str): Success message text
- icon (bool or str): Show success icon or custom icon name
Returns:
None
"""
def info(body, icon=True):
"""
Display an informational message with blue styling.
Parameters:
- body (str): Information message text
- icon (bool or str): Show info icon or custom icon name
Returns:
None
"""
def warning(body, icon=True):
"""
Display a warning message with yellow styling.
Parameters:
- body (str): Warning message text
- icon (bool or str): Show warning icon or custom icon name
Returns:
None
"""
def error(body, icon=True):
"""
Display an error message with red styling.
Parameters:
- body (str): Error message text
- icon (bool or str): Show error icon or custom icon name
Returns:
None
"""
def exception(exception):
"""
Display an exception with full traceback.
Parameters:
- exception (Exception): Exception object to display
Returns:
None
"""Display temporary notifications and celebratory animations.
def toast(body, icon=None):
"""
Display a toast notification that appears temporarily.
Parameters:
- body (str): Toast message text
- icon (str): Optional icon name or emoji
Returns:
None
"""
def balloons():
"""
Display celebratory balloons animation.
Returns:
None
"""
def snow():
"""
Display falling snow animation.
Returns:
None
"""Collect user feedback and interaction responses.
def feedback(options, key=None, disabled=False, on_change=None, args=None, kwargs=None):
"""
Display a feedback widget for collecting user sentiment.
Parameters:
- options (str): Type of feedback options ('thumbs' or 'faces')
- key (str): Unique key for the widget
- disabled (bool): Disable the widget
- on_change (callable): Function to call when feedback changes
- args (tuple): Arguments to pass to on_change function
- kwargs (dict): Keyword arguments to pass to on_change function
Returns:
dict or None: Feedback score and sentiment information
"""
def badge(label, background_color=None):
"""
Display a badge element with optional color.
Parameters:
- label (str): Badge text
- background_color (str): Badge background color (hex, CSS name, or None)
Returns:
None
"""import streamlit as st
from PIL import Image
import numpy as np
# Display image from file
st.subheader("Image from File")
try:
image = Image.open("sample_image.jpg")
st.image(image, caption="Sample Image", use_container_width=True)
except FileNotFoundError:
st.error("Image file not found")
# Display image from URL
st.subheader("Image from URL")
st.image(
"https://static.streamlit.io/examples/cat.jpg",
caption="Cat from URL",
width=300
)
# Display numpy array as image
st.subheader("Generated Image")
image_array = np.random.randint(0, 255, (200, 200, 3), dtype=np.uint8)
st.image(image_array, caption="Random noise image", clamp=True)
# Display multiple images
st.subheader("Image Gallery")
images = [
"https://static.streamlit.io/examples/cat.jpg",
"https://static.streamlit.io/examples/dog.jpg"
]
captions = ["Cat", "Dog"]
st.image(images, caption=captions, width=200)# Display audio player
st.subheader("Audio Player")
# From file
try:
audio_file = open("sample_audio.wav", "rb")
audio_bytes = audio_file.read()
st.audio(audio_bytes, format="audio/wav")
audio_file.close()
except FileNotFoundError:
st.info("Audio file not available for demo")
# From URL
st.audio("https://www.soundjay.com/misc/sounds/bell-ringing-05.wav")
# Video player
st.subheader("Video Player")
# Local video file
try:
video_file = open("sample_video.mp4", "rb")
video_bytes = video_file.read()
st.video(video_bytes, start_time=10) # Start at 10 seconds
video_file.close()
except FileNotFoundError:
st.info("Video file not available for demo")
# Video with subtitles
st.video(
"sample_video.mp4",
subtitles="subtitles.vtt",
loop=True,
autoplay=False
)# Display PDF document
st.subheader("PDF Document")
try:
with open("document.pdf", "rb") as pdf_file:
pdf_bytes = pdf_file.read()
st.pdf(pdf_bytes, width=700)
except FileNotFoundError:
st.info("PDF file not available for demo")
# PDF from URL
st.pdf("https://example.com/sample.pdf", height=400)# Different types of status messages
st.subheader("Status Messages")
st.success("✅ Operation completed successfully!")
st.info("ℹ️ Here's some helpful information.")
st.warning("⚠️ Please review your input carefully.")
st.error("❌ An error occurred during processing.")
# Status messages with custom icons
st.success("Data saved!", icon="💾")
st.info("New features available", icon="🚀")
st.warning("Server maintenance scheduled", icon="🔧")
st.error("Connection failed", icon="🌐")
# Exception display
try:
result = 1 / 0
except ZeroDivisionError as e:
st.exception(e)# Toast notifications (appear temporarily)
if st.button("Show Success Toast"):
st.toast("Success! Operation completed.", icon="✅")
if st.button("Show Info Toast"):
st.toast("Information: Check your email.", icon="📧")
if st.button("Show Warning Toast"):
st.toast("Warning: Please save your work.", icon="⚠️")
if st.button("Show Custom Toast"):
st.toast("Custom notification!", icon="🎉")# Celebratory animations
col1, col2 = st.columns(2)
with col1:
if st.button("🎈 Celebrate with Balloons"):
st.balloons()
st.success("Congratulations! 🎉")
with col2:
if st.button("❄️ Let it Snow"):
st.snow()
st.info("Winter wonderland! ⛄")# Feedback widgets
st.subheader("Feedback Collection")
# Thumbs up/down feedback
feedback_1 = st.feedback("thumbs", key="feedback_1")
if feedback_1:
st.write(f"Feedback received: {feedback_1}")
# Faces feedback (1-5 scale)
feedback_2 = st.feedback("faces", key="feedback_2")
if feedback_2:
st.write(f"Rating: {feedback_2['score']}/5")
# Badge display
st.subheader("Badges")
col1, col2, col3 = st.columns(3)
with col1:
st.badge("New", background_color="#FF6B6B")
with col2:
st.badge("Premium", background_color="#4ECDC4")
with col3:
st.badge("Beta", background_color="#45B7D1")# Interactive media controls
st.subheader("Interactive Media Player")
# Media controls
col1, col2 = st.columns([3, 1])
with col1:
# Video player with user controls
autoplay = st.checkbox("Autoplay")
loop_video = st.checkbox("Loop")
muted = st.checkbox("Muted")
start_time = st.slider("Start time (seconds)", 0, 300, 0)
with col2:
st.write("**Player Settings**")
if st.button("Load Video"):
st.video(
"sample_video.mp4",
autoplay=autoplay,
loop=loop_video,
muted=muted,
start_time=start_time
)# Status messages with follow-up actions
error_occurred = st.checkbox("Simulate error condition")
if error_occurred:
st.error("Database connection failed!", icon="🔌")
col1, col2, col3 = st.columns(3)
with col1:
if st.button("Retry Connection"):
st.success("Connection restored!")
with col2:
if st.button("Check Status"):
st.info("System status: All services operational")
with col3:
if st.button("Contact Support"):
st.info("Support ticket created: #12345")
# Success with next steps
if st.button("Complete Process"):
st.success("✅ File uploaded successfully!")
st.balloons()
with st.expander("Next Steps"):
st.write("1. Review the uploaded data")
st.write("2. Configure processing options")
st.write("3. Start the analysis")# Conditional media based on user selection
media_type = st.selectbox(
"Select media type:",
["None", "Image", "Audio", "Video", "PDF"]
)
if media_type == "Image":
st.image(
"https://static.streamlit.io/examples/cat.jpg",
caption="Sample image",
use_container_width=True
)
elif media_type == "Audio":
st.audio("https://www.soundjay.com/misc/sounds/bell-ringing-05.wav")
elif media_type == "Video":
st.video("https://sample-videos.com/zip/10/mp4/SampleVideo_1280x720_1mb.mp4")
elif media_type == "PDF":
st.info("PDF viewer would display here with actual PDF file")
else:
st.info("Select a media type to display content")Install with Tessl CLI
npx tessl i tessl/pypi-streamlit@1.49.0