Update app.py
Browse files
app.py
CHANGED
@@ -43,6 +43,16 @@ indexImg = 0
|
|
43 |
if "output_text" not in st.session_state:
|
44 |
st.session_state["output_text"] = ""
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
webrtc_ctx = webrtc_streamer(
|
48 |
key="virtual-keyboard",
|
@@ -51,14 +61,22 @@ webrtc_ctx = webrtc_streamer(
|
|
51 |
"iceServers": get_ice_servers(),
|
52 |
"iceTransportPolicy": "relay",
|
53 |
},
|
54 |
-
video_frame_callback=
|
55 |
-
frame, detector, segmentor, imgList, indexImg, keys, st.session_state
|
56 |
-
),
|
57 |
media_stream_constraints={"video": True, "audio": False},
|
58 |
async_processing=True,
|
59 |
)
|
60 |
-
|
61 |
-
|
62 |
# Output text display
|
63 |
st.subheader("Output Text")
|
64 |
-
st.text_area("Live Input:", value=st.session_state["output_text"], height=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
if "output_text" not in st.session_state:
|
44 |
st.session_state["output_text"] = ""
|
45 |
|
46 |
+
# Create a thread-safe queue for passing results from callback
|
47 |
+
result_queue = queue.Queue()
|
48 |
+
|
49 |
+
# Function to process video frame callback
|
50 |
+
def video_frame_callback(frame):
|
51 |
+
# Process the frame asynchronously
|
52 |
+
output_text = process_video_frame(frame, detector, segmentor, imgList, indexImg, keys, st.session_state)
|
53 |
+
# Put the processed output text into the queue
|
54 |
+
result_queue.put(output_text)
|
55 |
+
return frame # Return the processed frame for display
|
56 |
|
57 |
webrtc_ctx = webrtc_streamer(
|
58 |
key="virtual-keyboard",
|
|
|
61 |
"iceServers": get_ice_servers(),
|
62 |
"iceTransportPolicy": "relay",
|
63 |
},
|
64 |
+
video_frame_callback=video_frame_callback,
|
|
|
|
|
65 |
media_stream_constraints={"video": True, "audio": False},
|
66 |
async_processing=True,
|
67 |
)
|
|
|
|
|
68 |
# Output text display
|
69 |
st.subheader("Output Text")
|
70 |
+
st.text_area("Live Input:", value=st.session_state["output_text"], height=200)
|
71 |
+
|
72 |
+
|
73 |
+
# Display live output text by checking for results in the queue
|
74 |
+
if st.checkbox("Show live input", value=True):
|
75 |
+
if webrtc_ctx.state.playing:
|
76 |
+
labels_placeholder = st.empty()
|
77 |
+
while True:
|
78 |
+
# Get the result from the queue
|
79 |
+
if not result_queue.empty():
|
80 |
+
result = result_queue.get()
|
81 |
+
st.session_state["output_text"] = result
|
82 |
+
labels_placeholder.text(result)
|