fadzwan commited on
Commit
aaea07f
·
verified ·
1 Parent(s): ffec487

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +35 -2
src/streamlit_app.py CHANGED
@@ -266,6 +266,39 @@ if st.button("Show Band Power Chart (TP9)"):
266
 
267
  except Exception as e:
268
  st.error(f"❌ Error: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
 
270
-
271
-
 
266
 
267
  except Exception as e:
268
  st.error(f"❌ Error: {str(e)}")
269
+ # Button to show EEG animation
270
+ if st.button("Show Animated EEG Trace (TP9)"):
271
+ try:
272
+ # Setup figure and axes
273
+ fig, ax = plt.subplots()
274
+ line, = ax.plot([], [], lw=2)
275
+ ax.set_xlim(0, 5)
276
+ ax.set_ylim(np.min(tp10_filtered_mne), np.max(tp10_filtered_mne))
277
+ ax.set_title("Animated EEG Trace - TP9")
278
+
279
+ # Init function
280
+ def init():
281
+ line.set_data([], [])
282
+ return line,
283
+
284
+ # Animation function
285
+ def animate(i):
286
+ start = i * int(sampling_rate * 0.1)
287
+ end = start + int(sampling_rate * 5)
288
+ x = np.arange(start, end) / sampling_rate
289
+ y = tp10_filtered_mne[start:end]
290
+ line.set_data(x, y)
291
+ return line,
292
+
293
+ # Create animation
294
+ ani = FuncAnimation(fig, animate, init_func=init, frames=100, interval=100, blit=True)
295
+
296
+ # Save to temporary file as GIF
297
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.gif') as tmpfile:
298
+ ani.save(tmpfile.name, writer='pillow', fps=10)
299
+ st.image(tmpfile.name, caption="Animated EEG Trace", use_column_width=True)
300
+
301
+ plt.close(fig) # Close figure to avoid duplicate rendering
302
 
303
+ except Exception as e:
304
+ st.error(f"❌ Error: {str(e)}")