Streamlit / app.py
SS8297's picture
Update app.py
ad76a8e
raw
history blame
1.06 kB
import streamlit as st
from streamlit_webrtc import webrtc_streamer
import av
import os
from twilio.rest import Client
os.environ["TWILIO_ACCOUNT_SID"] = "ACf1e76f3fd6e9cbca940decc4ed443c20"
os.environ["TWILIO_AUTH_TOKEN"] = "56a1d1ee494933269fe042706392ac9f"
def get_ice_servers():
try:
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
except KeyError:
logger.warning("TURN credentials are not set. Fallback to a free STUN server from Google.")
return [{"urls": ["stun:stun.l.google.com:19302"]}]
client = Client(account_sid, auth_token)
token = client.tokens.create()
return token.ice_servers
def video_frame_callback(frame):
img = frame.to_ndarray(format="bgr24")
flipped = img[::-1,:,:] if flip else img
return av.VideoFrame.from_ndarray(flipped, format="bgr24")
flip = st.checkbox("Flip")
webrtc_streamer(
key="example",
video_frame_callback=video_frame_callback,
rtc_configuration={ "iceServers": get_ice_servers() }
)