Update src/streamlit_app.py
Browse files- src/streamlit_app.py +17 -7
src/streamlit_app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import cv2
|
2 |
import mediapipe as mp
|
3 |
import numpy as np
|
@@ -16,6 +17,9 @@ logging.getLogger('mediapipe').setLevel(logging.ERROR)
|
|
16 |
mp_pose = mp.solutions.pose
|
17 |
mp_drawing = mp.solutions.drawing_utils
|
18 |
|
|
|
|
|
|
|
19 |
pose = mp_pose.Pose(
|
20 |
static_image_mode=False,
|
21 |
min_detection_confidence=0.5,
|
@@ -26,17 +30,23 @@ pose = mp_pose.Pose(
|
|
26 |
|
27 |
# Initialize pyttsx3 for text-to-speech
|
28 |
engine = pyttsx3.init()
|
29 |
-
engine.setProperty('rate', 150)
|
30 |
-
engine.setProperty('volume', 0.9)
|
31 |
|
32 |
-
#
|
33 |
def speak(text, force=False):
|
34 |
if not hasattr(speak, 'last_text') or speak.last_text != text or force:
|
35 |
speak.last_text = text
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
# Define scaling factor for angles
|
42 |
ANGLE_SCALE = 1
|
|
|
1 |
+
import os
|
2 |
import cv2
|
3 |
import mediapipe as mp
|
4 |
import numpy as np
|
|
|
17 |
mp_pose = mp.solutions.pose
|
18 |
mp_drawing = mp.solutions.drawing_utils
|
19 |
|
20 |
+
# Set MediaPipe cache directory (optional, as Dockerfile sets MEDIAPIPE_CACHE_DIR)
|
21 |
+
os.makedirs("/app/mediapipe_models", exist_ok=True)
|
22 |
+
|
23 |
pose = mp_pose.Pose(
|
24 |
static_image_mode=False,
|
25 |
min_detection_confidence=0.5,
|
|
|
30 |
|
31 |
# Initialize pyttsx3 for text-to-speech
|
32 |
engine = pyttsx3.init()
|
33 |
+
engine.setProperty('rate', 150)
|
34 |
+
engine.setProperty('volume', 0.9)
|
35 |
|
36 |
+
# Modified speak function to display instructions in Streamlit UI
|
37 |
def speak(text, force=False):
|
38 |
if not hasattr(speak, 'last_text') or speak.last_text != text or force:
|
39 |
speak.last_text = text
|
40 |
+
st.write(f"Instruction: {text}")
|
41 |
+
try:
|
42 |
+
def run_speech():
|
43 |
+
engine.say(text)
|
44 |
+
engine.runAndWait()
|
45 |
+
threading.Thread(target=run_speech, daemon=True).start()
|
46 |
+
except:
|
47 |
+
pass # Skip audio errors in server environment
|
48 |
+
|
49 |
+
|
50 |
|
51 |
# Define scaling factor for angles
|
52 |
ANGLE_SCALE = 1
|