whitphx HF staff commited on
Commit
7901a5c
1 Parent(s): ceec677

Add streamlit-webrtc sample

Browse files
Files changed (2) hide show
  1. app.py +22 -2
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,4 +1,24 @@
1
  import streamlit as st
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from streamlit_webrtc import webrtc_streamer
3
+ import av
4
 
5
+
6
+ flip = st.checkbox("Flip")
7
+
8
+
9
+ def video_frame_callback(frame):
10
+ img = frame.to_ndarray(format="bgr24")
11
+
12
+ flipped = img[::-1,:,:] if flip else img
13
+
14
+ return av.VideoFrame.from_ndarray(flipped, format="bgr24")
15
+
16
+
17
+ webrtc_streamer(
18
+ key="sample",
19
+ video_frame_callback=video_frame_callback,
20
+ media_stream_constraints={"video": True, "audio": False},
21
+ rtc_configuration={ # Add this config
22
+ "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
23
+ }
24
+ )
requirements.txt ADDED
@@ -0,0 +1 @@
 
1
+ streamlit-webrtc