Spaces:
Sleeping
Sleeping
samyak152002
commited on
Commit
•
2e1ae85
1
Parent(s):
94dbf41
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
# Function to process the CSV file
|
6 |
+
def process_csv():
|
7 |
+
df = pd.read_csv("mitbih_train.csv", header=None)
|
8 |
+
M = df.values
|
9 |
+
X = M[:, :-1]
|
10 |
+
y = M[:, -1].astype(int)
|
11 |
+
|
12 |
+
C0 = np.argwhere(y == 0).flatten()
|
13 |
+
C1 = np.argwhere(y == 1).flatten()
|
14 |
+
C2 = np.argwhere(y == 2).flatten()
|
15 |
+
C3 = np.argwhere(y == 3).flatten()
|
16 |
+
C4 = np.argwhere(y == 4).flatten()
|
17 |
+
|
18 |
+
# Select sample indices
|
19 |
+
sample_data = {
|
20 |
+
"Cat_N": X[C0[0], :].tolist(),
|
21 |
+
"Cat_S": X[C1[0], :].tolist(),
|
22 |
+
"Cat_V": X[C2[0], :].tolist(),
|
23 |
+
"Cat_F": X[C3[0], :].tolist(),
|
24 |
+
"Cat_Q": X[C4[0], :].tolist(),
|
25 |
+
"time": (np.arange(0, 187) * 8 / 1000).tolist() # time axis
|
26 |
+
}
|
27 |
+
|
28 |
+
return sample_data
|
29 |
+
|
30 |
+
# Gradio Interface for visualizing ECG data
|
31 |
+
def get_ecg_data():
|
32 |
+
return process_csv()
|
33 |
+
|
34 |
+
# Set up Gradio Interface
|
35 |
+
iface = gr.Interface(
|
36 |
+
fn=get_ecg_data,
|
37 |
+
inputs=[],
|
38 |
+
outputs="json",
|
39 |
+
live=False
|
40 |
+
)
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
iface.launch(share=True)
|