File size: 1,052 Bytes
2e1ae85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
import numpy as np

# Function to process the CSV file
def process_csv():
    df = pd.read_csv("mitbih_train.csv", header=None)
    M = df.values
    X = M[:, :-1]
    y = M[:, -1].astype(int)
    
    C0 = np.argwhere(y == 0).flatten()
    C1 = np.argwhere(y == 1).flatten()
    C2 = np.argwhere(y == 2).flatten()
    C3 = np.argwhere(y == 3).flatten()
    C4 = np.argwhere(y == 4).flatten()
    
    # Select sample indices
    sample_data = {
        "Cat_N": X[C0[0], :].tolist(),
        "Cat_S": X[C1[0], :].tolist(),
        "Cat_V": X[C2[0], :].tolist(),
        "Cat_F": X[C3[0], :].tolist(),
        "Cat_Q": X[C4[0], :].tolist(),
        "time": (np.arange(0, 187) * 8 / 1000).tolist()  # time axis
    }
    
    return sample_data

# Gradio Interface for visualizing ECG data
def get_ecg_data():
    return process_csv()

# Set up Gradio Interface
iface = gr.Interface(
    fn=get_ecg_data,
    inputs=[],
    outputs="json",
    live=False
)

if __name__ == "__main__":
    iface.launch(share=True)