Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +51 -0
src/streamlit_app.py
CHANGED
|
@@ -100,3 +100,54 @@ if generate_button:
|
|
| 100 |
st.image(gif_path, caption="EEG Topomap Animation")
|
| 101 |
except Exception as e:
|
| 102 |
st.error(f"❌ Error: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
st.image(gif_path, caption="EEG Topomap Animation")
|
| 101 |
except Exception as e:
|
| 102 |
st.error(f"❌ Error: {str(e)}")
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
plot_waveform_button = st.button("Plot TP9 Waveforms")
|
| 106 |
+
|
| 107 |
+
if plot_waveform_button:
|
| 108 |
+
try:
|
| 109 |
+
# Download and read CSV
|
| 110 |
+
response = requests.get(csv_url)
|
| 111 |
+
response.raise_for_status()
|
| 112 |
+
data = pd.read_csv(io.StringIO(response.text))
|
| 113 |
+
st.write(f"Loaded data with shape: {data.shape}")
|
| 114 |
+
|
| 115 |
+
# Extract timestamps and TP9
|
| 116 |
+
timestamps = data['timestamps'] if 'timestamps' in data.columns else data['TimeStamp']
|
| 117 |
+
tp10_raw = data['TP9']
|
| 118 |
+
|
| 119 |
+
# Calculate sampling rate
|
| 120 |
+
time_diffs = np.diff(timestamps)
|
| 121 |
+
average_interval = np.mean(time_diffs)
|
| 122 |
+
sampling_rate = 1 / average_interval
|
| 123 |
+
|
| 124 |
+
# Create MNE Raw object
|
| 125 |
+
info = mne.create_info(ch_names=['TP9'], sfreq=sampling_rate, ch_types='eeg')
|
| 126 |
+
raw = mne.io.RawArray(np.array([tp10_raw]), info)
|
| 127 |
+
|
| 128 |
+
# Apply bandpass filter
|
| 129 |
+
raw.filter(1, 50, fir_design='firwin')
|
| 130 |
+
tp10_filtered_mne = raw.get_data()[0]
|
| 131 |
+
|
| 132 |
+
# Plot raw waveform
|
| 133 |
+
fig_raw, ax_raw = plt.subplots(figsize=(12, 4))
|
| 134 |
+
ax_raw.plot(timestamps, tp10_raw, label='TP9', alpha=0.6, color='blue')
|
| 135 |
+
ax_raw.set_title('Raw Waveform of TP9')
|
| 136 |
+
ax_raw.set_xlabel('Time (seconds)')
|
| 137 |
+
ax_raw.set_ylabel('Amplitude')
|
| 138 |
+
ax_raw.legend()
|
| 139 |
+
ax_raw.grid(True)
|
| 140 |
+
st.pyplot(fig_raw)
|
| 141 |
+
|
| 142 |
+
# Plot filtered waveform
|
| 143 |
+
fig_filtered, ax_filtered = plt.subplots(figsize=(12, 4))
|
| 144 |
+
ax_filtered.plot(timestamps, tp10_filtered_mne, label='TP9 (1-50Hz)', linewidth=1.5, color='green')
|
| 145 |
+
ax_filtered.set_title('Filtered Waveform of TP9')
|
| 146 |
+
ax_filtered.set_xlabel('Time (seconds)')
|
| 147 |
+
ax_filtered.set_ylabel('Amplitude')
|
| 148 |
+
ax_filtered.legend()
|
| 149 |
+
ax_filtered.grid(True)
|
| 150 |
+
st.pyplot(fig_filtered)
|
| 151 |
+
|
| 152 |
+
except Exception as e:
|
| 153 |
+
st.error(f"❌ Error: {str(e)}")
|