- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersonalai_dash.py
More file actions
Latest commit
78 lines (63 loc) · 2.42 KB
/
Copy pathpersonalai_dash.py
File metadata and controls
78 lines (63 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
importcv2
importstreamlitasst
importnumpyasnp
importmediapipeasmp
frommediapipe.tasksimportpython
frommediapipe.framework.formatsimportlandmark_pb2
importqueue
importpandasaspd
frompersonal_aiimport*
fromtimeimporttime, sleep
st.set_page_config(
layout="wide"
)
# personalAI = PersonalAI("IMG_2149.mov")
personalAI=PersonalAI("IMG_2149.mov")
personalAI.run()
st.sidebar.title("AI Personal Trainer")
display_charts=st.sidebar.checkbox('Display charts', value=True)
reset=st.sidebar.button("Reset")
col1, col2=st.columns(2)
# run = st.sidebar.checkbox('Ligar Webcam')
# landmarks = st.sidebar.checkbox('Mapeamento facial')
frame, landmarks, ts=personalAI.image_q.get()
df_nodes_x=pd.DataFrame()
df_nodes_y=pd.DataFrame()
placeholder=st.empty()
c=0
status="relaxed"
useful_points= [11, 12, 24, 23, 14, 13]
count=0
whileTrue:
frame, landmarks, ts=personalAI.image_q.get()
ifts=="done": break
iflen(landmarks.pose_landmarks) >0:
frame, elbow_angle=personalAI.draw_angle(frame, landmarks, 12, 14, 16)
frame, hip_angle=personalAI.draw_angle(frame, landmarks, 11, 23, 25)
df_y=pd.DataFrame([i.yforiin [iforiinlandmarks.pose_landmarks[0]]]).rename(columns={0: ts}).transpose()
df_nodes_y=pd.concat([df_nodes_y, df_y])
# Pushup Logic
ifelbow_angle>150andhip_angle>170:
status="ready"
dir="down"
ifstatus=="ready":
ifdir=="down"andelbow_angle<60:
dir="up"
count+=0.5
ifdir=="up"andelbow_angle>100:
dir="down"
count+=0.5
# frame = cv2.putText(frame, status, (70, 70),
# cv2.FONT_HERSHEY_PLAIN, 5, (20,20,20), 3)
# frame = cv2.putText(frame, str(int(count)), (frame.shape[1]-100, 100),
# cv2.FONT_HERSHEY_PLAIN, 8, (20,20,20), 3)
withplaceholder.container():
col1, col2=st.columns([0.4, 0.6])
status_m=f":red[{status}]"ifstatus=="relaxed"elsef":green[{status}]"
col2.markdown("### **Status:** "+status_m)
col2.markdown(f"### Count: {int(count)}")
col2.divider()
col1.image(frame)
ifc%2==0anddisplay_charts:
col2.line_chart(df_nodes_y[useful_points])
c+=1