Working with Images, Audios, and Videos with Streamlit

Multimedia Streamlit Feature

You can easily add references, introductions, explanations, etc in the form of media files for your ML/data app seamlessly now.

Streamlit offers to easily upload your media files like images, audio, and videos or embed them from a website.

Table of Contents


You can add images from your device or simply provide a URL to embed them in your workflow using st.image()and PIL library of Python

import streamlit as st

from PIL import Image

st.write("## Image example:- ")

img = Image.open("dogs.jpeg")
Image Streamlit 1

You may simply embed an image from a link using st.image(<URL>)

#From URL

st.write("## Image from URL example:- ")

Image Url Streamlit


Uploading videos to your ML app is easy with Streamlit using function st.video(). You may also specify a start time of the video using property start_time (in seconds) from where the video must begin.

video_file = open("sample.mp4", "rb").read()

st.video(video_file, start_time = 3)

There are 2 play buttons but one is inside the screen recording. Please click on the lower one to play the video.

You can also embed video from any free video-sharing website like YouTube using st.video(<URL>)

Url Video Streamlit


You can showcase audio in your Streamlit app using st.audio() and embed from a website using st.audio(<URL>)

Note that the URL from where you are embedding the audio from must contain a valid audio file extension like mp3, wav, etc.

st.write("## Audio file example")

audio_file = open("audio-sample.mp3", "rb")

Audio File Streamlit