Spaces:
Sleeping
Sleeping
Milo Sobral
commited on
Commit
·
b0f3e42
1
Parent(s):
7d40d1a
Fixed small issue, camera ready V1
Browse files- portiloop/src/demo/demo.py +21 -13
portiloop/src/demo/demo.py
CHANGED
@@ -68,18 +68,26 @@ def do_treatment(csv_file, filtering, threshold, detect_channel, freq, spindle_f
|
|
68 |
# Add data to plotting buffer
|
69 |
points.append(filtered_point[0])
|
70 |
|
|
|
|
|
|
|
|
|
71 |
# Plot the data
|
72 |
-
if index % (10 * freq) == 0:
|
73 |
plt.close()
|
74 |
fig = plt.figure(figsize=(20, 10))
|
75 |
plt.clf()
|
76 |
-
plt.plot(points[-10 * freq:], label="Data")
|
77 |
# Draw vertical lines for activations
|
78 |
for index in get_activations(activations[-10 * freq:]):
|
79 |
-
plt.axvline(x=index, color='r', label="Fast Stimulation")
|
80 |
if spindle_detection_mode != 'Fast':
|
81 |
for index in get_activations(delayed_activations[-10 * freq:]):
|
82 |
-
plt.axvline(x=index, color='g', label="Delayed Stimulation")
|
|
|
|
|
|
|
|
|
83 |
yield fig, None
|
84 |
|
85 |
# Put all points and activations back in numpy arrays
|
@@ -93,13 +101,13 @@ def do_treatment(csv_file, filtering, threshold, detect_channel, freq, spindle_f
|
|
93 |
|
94 |
yield None, "output.csv"
|
95 |
|
96 |
-
|
97 |
-
def get_activations(activations):
|
98 |
-
return [i for i, x in enumerate(activations) if x == 1]
|
99 |
|
100 |
|
101 |
with gr.Blocks() as demo:
|
102 |
-
gr.Markdown("
|
|
|
|
|
103 |
|
104 |
# Row containing all inputs:
|
105 |
with gr.Row():
|
@@ -110,15 +118,15 @@ with gr.Blocks() as demo:
|
|
110 |
# Threshold value
|
111 |
threshold = gr.Slider(0, 1, value=0.82, step=0.01, label="Threshold", interactive=True)
|
112 |
# Detection Channel
|
113 |
-
detect_column = gr.Dropdown(choices=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"], value="1", label="Detection Column", interactive=True)
|
114 |
# Frequency
|
115 |
-
freq = gr.Dropdown(choices=["100", "200", "250", "256", "500", "512", "1000", "1024"], value="250", label="Frequency", interactive=True)
|
116 |
# Spindle Frequency
|
117 |
-
spindle_freq = gr.Slider(10, 16, value=12, step=1, label="Spindle Frequency", interactive=True)
|
118 |
# Spindle Detection Mode
|
119 |
spindle_detection_mode = gr.Dropdown(choices=["Fast", "Peak", "Valley"], value="Peak", label="Spindle Detection Mode", interactive=True)
|
120 |
# Time to buffer
|
121 |
-
time_to_buffer = gr.Slider(0, 1, value=0, step=0.01, label="Time to Buffer", interactive=True)
|
122 |
|
123 |
# Output plot
|
124 |
output_plot = gr.Plot()
|
@@ -134,4 +142,4 @@ with gr.Blocks() as demo:
|
|
134 |
run_inference.click(fn=do_treatment, inputs=[csv_file, filtering, threshold, detect_column, freq, spindle_freq, spindle_detection_mode, time_to_buffer], outputs=[output_plot, output_array])
|
135 |
|
136 |
demo.queue()
|
137 |
-
demo.launch()
|
|
|
68 |
# Add data to plotting buffer
|
69 |
points.append(filtered_point[0])
|
70 |
|
71 |
+
# Function to return a list of all indexes where activations have happened
|
72 |
+
def get_activations(activations):
|
73 |
+
return [i for i, x in enumerate(activations) if x == 1]
|
74 |
+
|
75 |
# Plot the data
|
76 |
+
if index % (10 * freq) == 0 and index >= (10 * freq):
|
77 |
plt.close()
|
78 |
fig = plt.figure(figsize=(20, 10))
|
79 |
plt.clf()
|
80 |
+
plt.plot(np.linspace(0, 10, num=freq*10), points[-10 * freq:], label="Data")
|
81 |
# Draw vertical lines for activations
|
82 |
for index in get_activations(activations[-10 * freq:]):
|
83 |
+
plt.axvline(x=index / freq, color='r', label="Fast Stimulation")
|
84 |
if spindle_detection_mode != 'Fast':
|
85 |
for index in get_activations(delayed_activations[-10 * freq:]):
|
86 |
+
plt.axvline(x=index / freq, color='g', label="Delayed Stimulation")
|
87 |
+
# Add axis titles and legend
|
88 |
+
plt.legend()
|
89 |
+
plt.xlabel("Time (s)")
|
90 |
+
plt.ylabel("Amplitude")
|
91 |
yield fig, None
|
92 |
|
93 |
# Put all points and activations back in numpy arrays
|
|
|
101 |
|
102 |
yield None, "output.csv"
|
103 |
|
104 |
+
|
|
|
|
|
105 |
|
106 |
|
107 |
with gr.Blocks() as demo:
|
108 |
+
gr.Markdown("# Portiloop Demo")
|
109 |
+
gr.Markdown("This Demo takes as input a csv file containing EEG data and outputs a csv file with the following added: \n * The data filtered by the Portiloop online filter \n * The stimulations made by Portiloop.")
|
110 |
+
gr.Markdown("Upload your CSV file and click **Run Inference** to start the processing...")
|
111 |
|
112 |
# Row containing all inputs:
|
113 |
with gr.Row():
|
|
|
118 |
# Threshold value
|
119 |
threshold = gr.Slider(0, 1, value=0.82, step=0.01, label="Threshold", interactive=True)
|
120 |
# Detection Channel
|
121 |
+
detect_column = gr.Dropdown(choices=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"], value="1", label="Detection Column in CSV", interactive=True)
|
122 |
# Frequency
|
123 |
+
freq = gr.Dropdown(choices=["100", "200", "250", "256", "500", "512", "1000", "1024"], value="250", label="Sampling Frequency (Hz)", interactive=True)
|
124 |
# Spindle Frequency
|
125 |
+
spindle_freq = gr.Slider(10, 16, value=12, step=1, label="Spindle Frequency (Hz)", interactive=True)
|
126 |
# Spindle Detection Mode
|
127 |
spindle_detection_mode = gr.Dropdown(choices=["Fast", "Peak", "Valley"], value="Peak", label="Spindle Detection Mode", interactive=True)
|
128 |
# Time to buffer
|
129 |
+
time_to_buffer = gr.Slider(0, 1, value=0.3, step=0.01, label="Time to Buffer (s)", interactive=True)
|
130 |
|
131 |
# Output plot
|
132 |
output_plot = gr.Plot()
|
|
|
142 |
run_inference.click(fn=do_treatment, inputs=[csv_file, filtering, threshold, detect_column, freq, spindle_freq, spindle_detection_mode, time_to_buffer], outputs=[output_plot, output_array])
|
143 |
|
144 |
demo.queue()
|
145 |
+
demo.launch(share=True)
|