ombhojane commited on
Commit
bf4a6e3
·
verified ·
1 Parent(s): ab74dbe

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -14
app.py CHANGED
@@ -33,8 +33,8 @@ class AIDancePartner:
33
  # Add playback controls
34
  play_speed = st.sidebar.slider("Playback Speed", 0.1, 2.0, 1.0, 0.1)
35
 
36
- # Add play/pause button
37
- is_playing = st.sidebar.button("Play/Pause")
38
 
39
  if video_file:
40
  self.process_video(video_file, mode, play_speed, is_playing)
@@ -59,6 +59,10 @@ class AIDancePartner:
59
  # Initialize progress bar
60
  progress_bar = st.progress(0)
61
 
 
 
 
 
62
  # Store video frames and AI sequences
63
  frames = []
64
  ai_sequences = []
@@ -81,12 +85,18 @@ class AIDancePartner:
81
  frames.append(frame)
82
  ai_sequences.append(ai_frame)
83
 
 
 
 
 
 
 
 
84
  # Playback loop
85
  frame_count = 0
86
- play = True if is_playing else False
87
 
88
- while True:
89
- if play:
90
  if frame_count >= len(frames):
91
  frame_count = 0
92
 
@@ -114,15 +124,15 @@ class AIDancePartner:
114
  # Control playback speed
115
  time.sleep(1 / (fps * play_speed))
116
  frame_count += 1
117
-
118
- # Check for play/pause button
119
- if st.sidebar.button("Stop"):
120
- break
121
-
122
- # Add replay button
123
- if frame_count >= len(frames):
124
- if st.sidebar.button("Replay"):
125
- frame_count = 0
126
 
127
  # Cleanup
128
  cap.release()
 
33
  # Add playback controls
34
  play_speed = st.sidebar.slider("Playback Speed", 0.1, 2.0, 1.0, 0.1)
35
 
36
+ # Add play/pause button with unique key
37
+ is_playing = st.sidebar.button("Play/Pause", key="play_pause_button")
38
 
39
  if video_file:
40
  self.process_video(video_file, mode, play_speed, is_playing)
 
59
  # Initialize progress bar
60
  progress_bar = st.progress(0)
61
 
62
+ # Initialize play state in session state
63
+ if 'play_state' not in st.session_state:
64
+ st.session_state.play_state = is_playing
65
+
66
  # Store video frames and AI sequences
67
  frames = []
68
  ai_sequences = []
 
85
  frames.append(frame)
86
  ai_sequences.append(ai_frame)
87
 
88
+ # Playback controls in sidebar
89
+ col1, col2 = st.sidebar.columns(2)
90
+ with col1:
91
+ stop_button = st.button("Stop", key="stop_button")
92
+ with col2:
93
+ replay_button = st.button("Replay", key="replay_button")
94
+
95
  # Playback loop
96
  frame_count = 0
 
97
 
98
+ while not stop_button and frame_count < len(frames):
99
+ if st.session_state.play_state:
100
  if frame_count >= len(frames):
101
  frame_count = 0
102
 
 
124
  # Control playback speed
125
  time.sleep(1 / (fps * play_speed))
126
  frame_count += 1
127
+
128
+ # Handle replay
129
+ if replay_button:
130
+ frame_count = 0
131
+ st.session_state.play_state = True
132
+
133
+ # Toggle play state when play/pause button is pressed
134
+ if is_playing:
135
+ st.session_state.play_state = not st.session_state.play_state
136
 
137
  # Cleanup
138
  cap.release()