Spaces:
Sleeping
Sleeping
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) |