Spaces:
Sleeping
Sleeping
Delete pages/1_📷️_Live_Stream.py
Browse files- pages/1_📷️_Live_Stream.py +0 -68
pages/1_📷️_Live_Stream.py
DELETED
@@ -1,68 +0,0 @@
|
|
1 |
-
import av
|
2 |
-
import os
|
3 |
-
import sys
|
4 |
-
import streamlit as st
|
5 |
-
from streamlit_webrtc import VideoHTMLAttributes, webrtc_streamer
|
6 |
-
from aiortc.contrib.media import MediaRecorder
|
7 |
-
|
8 |
-
|
9 |
-
BASE_DIR = os.path.abspath(os.path.join(__file__, '../../'))
|
10 |
-
sys.path.append(BASE_DIR)
|
11 |
-
|
12 |
-
|
13 |
-
from utils import get_mediapipe_pose
|
14 |
-
from process_frame import ProcessFrame
|
15 |
-
from thresholds import get_thresholds_beginner, get_thresholds_pro
|
16 |
-
|
17 |
-
|
18 |
-
st.title('Anju AI Fitness Trainer')
|
19 |
-
|
20 |
-
mode = st.radio('Select Mode', ['Beginner', 'Pro'], horizontal=True)
|
21 |
-
|
22 |
-
thresholds = None
|
23 |
-
|
24 |
-
if mode == 'Beginner':
|
25 |
-
thresholds = get_thresholds_beginner()
|
26 |
-
|
27 |
-
elif mode == 'Pro':
|
28 |
-
thresholds = get_thresholds_pro()
|
29 |
-
|
30 |
-
|
31 |
-
live_process_frame = ProcessFrame(thresholds=thresholds, flip_frame=True)
|
32 |
-
# Initialize face mesh solution
|
33 |
-
pose = get_mediapipe_pose()
|
34 |
-
|
35 |
-
|
36 |
-
if 'download' not in st.session_state:
|
37 |
-
st.session_state['download'] = False
|
38 |
-
|
39 |
-
output_video_file = f'output_live.flv'
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
def video_frame_callback(frame: av.VideoFrame):
|
44 |
-
frame = frame.to_ndarray(format="rgb24") # Decode and get RGB frame
|
45 |
-
frame, _ = live_process_frame.process(frame, pose) # Process frame
|
46 |
-
return av.VideoFrame.from_ndarray(frame, format="rgb24") # Encode and return BGR frame
|
47 |
-
|
48 |
-
|
49 |
-
def out_recorder_factory() -> MediaRecorder:
|
50 |
-
return MediaRecorder(output_video_file)
|
51 |
-
|
52 |
-
|
53 |
-
ctx = webrtc_streamer(
|
54 |
-
key="Squats-pose-analysis",
|
55 |
-
video_frame_callback=video_frame_callback,
|
56 |
-
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]}, # Add this config
|
57 |
-
media_stream_constraints={"video": {"width": {'min':480, 'ideal':480}}, "audio": False},
|
58 |
-
video_html_attrs=VideoHTMLAttributes(autoPlay=True, controls=False, muted=False),
|
59 |
-
out_recorder_factory=None
|
60 |
-
)
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|