Posters
Scale
Paper

Streamlit-WebRTC

Yuichi (@whitphx)

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

Streamlit turns a Python script into an interactive web app. Streamlit-WebRTC adds real-time camera and microphone streams to it: the component handles browser capture and WebRTC transport, and passes each frame to your Python code, where any library, such as a YOLO model, can process it. Everything lives in one script, with no frontend code.

❤️

app.py
  • Streamlit

  • Streamlit-WebRTC

  • Your Python code

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 framework that turns a script into an interactive web app. Each st.* call draws a UI element, with no frontend code.

  1. Python script
  2. streamlit run
  3. Web app
What is Streamlit-WebRTC?

A component that adds real-time camera and microphone streams to a Streamlit app and passes each frame to your Python code.

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