File size: 3,953 Bytes
0d338e8 34947c3 52a6df6 d79183c 4b2fe4e 52a6df6 4b2fe4e fe70231 4b2fe4e 336b4e0 52a6df6 d79183c 0d338e8 4196959 0d338e8 52a6df6 0d338e8 52a6df6 0d338e8 4b2fe4e 0d338e8 52a6df6 4b2fe4e 52a6df6 34947c3 4b2fe4e 34947c3 4b2fe4e 34947c3 af3ede9 0d338e8 4196959 0d338e8 52a6df6 0d338e8 52a6df6 0d338e8 4b2fe4e 0d338e8 52a6df6 4b2fe4e 52a6df6 34947c3 4b2fe4e 34947c3 4b2fe4e 34947c3 af3ede9 34947c3 0d338e8 336b4e0 0d338e8 69afee6 52a6df6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
import streamlit as st
from streamlit_webrtc import webrtc_streamer, get_hf_ice_servers, get_twilio_ice_servers, __version__ as st_webrtc_version
import aiortc
import logging
logging.basicConfig(level=logging.INFO)
aioice_logger = logging.getLogger("aioice")
aioice_logger.setLevel(logging.DEBUG)
aiortc_logger = logging.getLogger("aiortc")
aiortc_logger.setLevel(logging.DEBUG)
aiortc_rtcrtpreceiver_logger = logging.getLogger("aiortc.rtcrtpreceiver")
aiortc_rtcrtpreceiver_logger.setLevel(logging.INFO)
aiortc_rtcrtpsender_logger = logging.getLogger("aiortc.rtcrtpsender")
aiortc_rtcrtpsender_logger.setLevel(logging.INFO)
frontend_ice_type = st.selectbox("Frontend ICE type", ["Empty", "Google STUN", "Twilio STUN/TURN", "Twilio STUN/TURN and Google STUN", "HF TURN only", "HF TURN and Google STUN", "None configured"])
backend_ice_type = st.selectbox("Backend ICE type", ["Empty", "Google STUN", "Twilio STUN/TURN", "Twilio STUN/TURN and Google STUN", "HF TURN only", "HF TURN and Google STUN", "None configured"])
TWILIO_ICE_SERVERS = get_twilio_ice_servers(
twilio_sid=st.secrets["TWILIO_ACCOUNT_SID"],
twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
)
HF_ICE_SERVERS = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
# google_stun_ice_servers = [{"urls": ["stun:stun.l.google.com:19302"]}]
google_stun_ice_servers = [{"urls": "stun:stun.l.google.com:19302", "url": "stun:stun.l.google.com:19302"}]
if frontend_ice_type == "Empty":
frontend_rtc_configuration = {
"iceServers": []
}
elif frontend_ice_type == "Google STUN":
frontend_rtc_configuration = {
"iceServers": google_stun_ice_servers
}
elif frontend_ice_type == "Twilio STUN/TURN":
frontend_rtc_configuration = {
"iceServers": TWILIO_ICE_SERVERS
}
elif frontend_ice_type == "Twilio STUN/TURN and Google STUN":
frontend_rtc_configuration = {
"iceServers": google_stun_ice_servers + TWILIO_ICE_SERVERS
}
elif frontend_ice_type == "HF TURN only":
frontend_rtc_configuration = {
"iceServers": HF_ICE_SERVERS
}
elif frontend_ice_type == "HF TURN and Google STUN":
frontend_rtc_configuration = {
"iceServers": HF_ICE_SERVERS + google_stun_ice_servers
}
elif frontend_ice_type == "None configured":
frontend_rtc_configuration = None
if backend_ice_type == "Empty":
backend_rtc_configuration = {
"iceServers": []
}
elif backend_ice_type == "Google STUN":
backend_rtc_configuration = {
"iceServers": google_stun_ice_servers
}
elif backend_ice_type == "Twilio STUN/TURN":
backend_rtc_configuration = {
"iceServers": TWILIO_ICE_SERVERS
}
elif backend_ice_type == "Twilio STUN/TURN and Google STUN":
backend_rtc_configuration = {
"iceServers": google_stun_ice_servers + TWILIO_ICE_SERVERS + google_stun_ice_servers
}
elif backend_ice_type == "HF TURN only":
backend_rtc_configuration = {
"iceServers": HF_ICE_SERVERS
}
elif backend_ice_type == "HF TURN and Google STUN":
backend_rtc_configuration = {
"iceServers": HF_ICE_SERVERS + google_stun_ice_servers
}
elif backend_ice_type == "None configured":
backend_rtc_configuration = None
if st.checkbox("Add invalid TURN server"):
backend_rtc_configuration["iceServers"].append({
"urls":"turn:gradio-turn.com:80",
"username":"non-existing-username",
"credential":"non-existing-credential"
})
st.write("Frontend ICE configuration:", frontend_rtc_configuration)
st.write("Backend ICE configuration:", backend_rtc_configuration)
webrtc_streamer(
key="example",
media_stream_constraints={"video": True, "audio": False},
frontend_rtc_configuration=frontend_rtc_configuration,
server_rtc_configuration=backend_rtc_configuration,
)
st.write(f"Streamlit version: {st.__version__}")
st.write(f"Streamlit-WebRTC version: {st_webrtc_version}")
st.write(f"aiortc version: {aiortc.__version__}")
|