File size: 2,372 Bytes
7d40d1a
 
2cb7306
7d40d1a
 
2cb7306
 
 
 
 
111f264
b0f3e42
7d40d1a
111f264
 
 
 
 
7d40d1a
111f264
 
 
2cb7306
111f264
2cb7306
111f264
 
7d40d1a
111f264
 
 
 
 
 
7d40d1a
111f264
98fb56f
111f264
 
 
 
 
 
 
 
 
 
7d40d1a
111f264
 
 
 
 
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
import gradio as gr

from portiloop.src.demo.offline import run_offline

        
def on_upload_file(file):
    # Check if file extension is .xdf
    if file.name.split(".")[-1] != "xdf":
        raise gr.Error("Please upload a .xdf file.")
    else:
        return file.name


def main():
    with gr.Blocks(title="Portiloop") as demo:
        gr.Markdown("# Portiloop Demo")
        gr.Markdown("This Demo takes as input an XDF file coming from the Portiloop EEG device and allows you to convert it to CSV and perform the following actions:: \n * Filter the data offline \n * Perform offline spindle detection using Wamsley or Lacourse. \n * Simulate the Portiloop online filtering and spindle detection with different parameters.")
        gr.Markdown("Upload your XDF file and click **Run Inference** to start the processing...")

        with gr.Row():
            xdf_file_button = gr.UploadButton(label="Click to Upload", type="file", file_count="single")
            xdf_file_static = gr.File(label="XDF File", type='file', interactive=False)

            xdf_file_button.upload(on_upload_file, xdf_file_button, xdf_file_static)

            # Make a checkbox group for the options
            detect_filter = gr.CheckboxGroup(['Offline Filtering', 'Lacourse Detection', 'Wamsley Detection', 'Online Filtering', 'Online Detection'], type='index', label="Filtering/Detection options")

            # Threshold value
            threshold = gr.Slider(0, 1, value=0.82, step=0.01, label="Threshold", interactive=True)
            # Detection Channel
            detect_channel = gr.Dropdown(choices=["1", "2", "3", "4", "5", "6", "7", "8"], value="2", label="Detection Channel in XDF recording", interactive=True) 
            # Frequency
            freq = gr.Dropdown(choices=["100", "200", "250", "256", "500", "512", "1000", "1024"], value="250", label="Sampling Frequency (Hz)", interactive=True)

        output_array = gr.File(label="Output CSV File")

        run_inference = gr.Button(value="Run Inference")
        run_inference.click(
            fn=run_offline, 
            inputs=[
                xdf_file_static, 
                detect_filter,
                threshold, 
                detect_channel,
                freq], 
            outputs=[output_array])

    demo.queue()
    demo.launch(share=True)

if __name__ == "__main__":
    main()