Posters
Scale
Paper

Streamlit-WebRTC

Yuichiro Tachibana (@whitphx)

Build a complete real-time audio and video web app. Using only Python.

Add live camera and microphone input to a Streamlit app, process the media in Python, and return transformed video or audio through WebRTC. Display text, metadata, and metrics with Streamlit elements. Everything lives in one Python script, with no frontend code. Streamlit-WebRTC supplies the browser component and handles WebRTC transport.

❤️

app.pyPython
import av
import streamlit as st
from streamlit_webrtc import webrtc_streamer
from ultralytics import YOLO

model_name = st.selectbox(
    "YOLO model",
    ["yolo11n.pt", "yolo11s.pt", "yolov8n.pt"],
)

with st.spinner(f"Loading {model_name}..."):
    model = YOLO(model_name)

def process(frame: av.VideoFrame) -> av.VideoFrame:
    image = frame.to_ndarray(format="bgr24")
    result = model(image, verbose=False)[0]
    annotated = result.plot()
    return av.VideoFrame.from_ndarray(
        annotated, format="bgr24"
    )

webrtc_streamer(
    key="detection",
    video_frame_callback=process,
    media_stream_constraints={"video": True, "audio": False},
)
Real-time object detection
Streamlit application showing YOLO model selection and object detection boxes over a live webcam feed
Get started

Start with a Streamlit app

What is Streamlit?

A Python web UI framework for building interactive apps without frontend code.

What is Streamlit-WebRTC?
A custom component that plugs into an existing Streamlit app.
Install
uv add streamlit streamlit-webrtc
Run
uv run streamlit run app.py

Turn Python models into user-facing apps without adding a second language or implementing WebRTC. Streamlit-WebRTC provides three media roles: sinks consume input for Streamlit outputs, filters transform and return media, and sources generate media. Compose them independently for audio and video.

Streamlit-WebRTC media routing architectureWebRTC carries audio and video between the frontend and Python backend. The frontend has one input and one output. On the backend, Sink, Filter, and Source are arranged in parallel. The input branches to Sink and Filter. Output from Filter and Source merges before returning to the frontend.FRONTENDBACKEND · PYTHONINPUTcamera / micOUTPUTplayerWebRTCSINKsink_*_trackinput onlyFILTER*_frame_callbackinput → outputSOURCEsource_*_trackoutput onlyWebRTC
Preview of PuzMol recognizing a paper molecular model

Turn paper molecular models into 3D

Recognize a paper model, then show its 3D form and chemical properties.

VIDEO · FILTER + SIDE OUTPUT
Nori Yamamoto@yamnor · Aug 2022
A real-time speech-to-text app showing a live camera and partial transcript

Real-time speech-to-text without an external API

Stream microphone audio to a local speech recognizer and update the transcript.

AUDIO · SINK
Yuichiro@whitphx · May 2021