Fix webcam mode AttributeError by using MediaMode enum
Browse filesFix webcam mode AttributeError by using MediaMode enum
Fixed the AttributeError: 'str' object has no attribute 'name' when switching to webcam mode.
Changed the string value "recv" to use the proper MediaMode.RECV enum from streamlit_webrtc package.
This ensures the mode parameter has the .name attribute that webrtc_streamer() expects.
app.py
CHANGED
@@ -5,7 +5,7 @@ import numpy as np
|
|
5 |
import torch
|
6 |
from collections import deque
|
7 |
from transformers import AutoFeatureExtractor, AutoModelForVideoClassification
|
8 |
-
from streamlit_webrtc import webrtc_streamer, VideoTransformerBase, RTCConfiguration
|
9 |
|
10 |
# Constants
|
11 |
NUM_FRAMES = 16
|
@@ -29,7 +29,6 @@ st.title("Dashcam Accident Predictor")
|
|
29 |
st.write("**higher score = higher accident probability**")
|
30 |
|
31 |
# Function to run inference on a saved video file
|
32 |
-
|
33 |
def run_inference_on_video(video_path):
|
34 |
cap = cv2.VideoCapture(video_path)
|
35 |
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
@@ -96,7 +95,7 @@ else:
|
|
96 |
|
97 |
webrtc_streamer(
|
98 |
key="dashcam-webcam",
|
99 |
-
mode="recv"
|
100 |
rtc_configuration=RTCConfiguration({
|
101 |
"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
|
102 |
}),
|
|
|
5 |
import torch
|
6 |
from collections import deque
|
7 |
from transformers import AutoFeatureExtractor, AutoModelForVideoClassification
|
8 |
+
from streamlit_webrtc import webrtc_streamer, VideoTransformerBase, RTCConfiguration, MediaMode
|
9 |
|
10 |
# Constants
|
11 |
NUM_FRAMES = 16
|
|
|
29 |
st.write("**higher score = higher accident probability**")
|
30 |
|
31 |
# Function to run inference on a saved video file
|
|
|
32 |
def run_inference_on_video(video_path):
|
33 |
cap = cv2.VideoCapture(video_path)
|
34 |
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
95 |
|
96 |
webrtc_streamer(
|
97 |
key="dashcam-webcam",
|
98 |
+
mode=MediaMode.RECV, # Changed from "recv" string to MediaMode enum
|
99 |
rtc_configuration=RTCConfiguration({
|
100 |
"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
|
101 |
}),
|