Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added gallery probing #3

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
399e20f
update
RanaweeraHK Jul 11, 2024
cf04d50
Merge branch 'master' of https://github.com/RanaweeraHK/ECGAnalysisDa…
RanaweeraHK Jul 11, 2024
8e58c35
commit
RanaweeraHK Jul 11, 2024
3d202a8
added gallery probing
ParameswaranSajeenthiran Jul 11, 2024
50720ab
added tabs
ParameswaranSajeenthiran Jul 11, 2024
0733dc6
reorganized
ParameswaranSajeenthiran Jul 11, 2024
03345fe
Merge branch 'ParameswaranSajeenthiran:master' into master
RanaweeraHK Jul 15, 2024
d072aaa
feat: Add MLFlowLogger and dataset conversion scripts
RanaweeraHK Jul 15, 2024
26a0a2f
co
RanaweeraHK Jul 15, 2024
4b0529d
commit
RanaweeraHK Jul 15, 2024
fca4856
Merge pull request #5 from RanaweeraHK/dev
ParameswaranSajeenthiran Jul 15, 2024
75b4a06
Revert "Dev branch updated"
ParameswaranSajeenthiran Jul 15, 2024
061e29f
Merge pull request #6 from ParameswaranSajeenthiran/revert-5-dev
ParameswaranSajeenthiran Jul 15, 2024
5b75132
save
ParameswaranSajeenthiran Jul 15, 2024
29d9801
updated dev
RanaweeraHK Jul 16, 2024
a12922c
save
ParameswaranSajeenthiran Jul 17, 2024
b1ae0e9
merged
ParameswaranSajeenthiran Jul 17, 2024
0e72a3f
updated descriptive
ParameswaranSajeenthiran Jul 17, 2024
594e685
done
RanaweeraHK Jul 18, 2024
2f35fb6
save
ParameswaranSajeenthiran Aug 13, 2024
0f3ba37
merged thisara
ParameswaranSajeenthiran Aug 15, 2024
5f6a131
Update arrythmia_detection.py
ThisaraWeerakoon Aug 22, 2024
4c5c4b7
Add files via upload
ThisaraWeerakoon Aug 22, 2024
271f06a
Resolved merge conflicts and removed unnecessary binary file
RanaweeraHK Aug 24, 2024
d20857f
update
RanaweeraHK Aug 24, 2024
25383c6
update
RanaweeraHK Aug 24, 2024
e1d4af3
Merge pull request #12 from RanaweeraHK/dev
ParameswaranSajeenthiran Oct 12, 2024
2242ee8
done
RanaweeraHK Oct 14, 2024
8a5d154
Merge pull request #13 from RanaweeraHK/dev
ParameswaranSajeenthiran Oct 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added 101dat
Binary file not shown.
90 changes: 0 additions & 90 deletions Extract.py

This file was deleted.

Binary file modified README.md
Binary file not shown.
Binary file added __pycache__/h5_pt_dataloader.cpython-39.pyc
Binary file not shown.
227 changes: 127 additions & 100 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,118 +1,145 @@
#
# import numpy as np
# import pandas as pd
# import streamlit as st
# import wfdb
#
# # from loguru import logger
#
# from page.PreProccessing import Preprocess
# from page.Descriptive_Analysis import DescriptiveAnalysis
# from page.Predictive_Analysis import PredictiveAnalysis
# from utils.sidebar import sidebar_caption
#
# #
# # # Config the whole app
# # st.set_page_config(
# # page_title="A Dashboard Template",
# # page_icon="🧊",
# # layout="wide",
# # initial_sidebar_state="expanded",
# # )
# #
#
# # @st.cache()
# def fake_data():
# """some fakest.chch data"""
#
# dt = pd.date_range("2021-01-01", "2021-03-01")
# df = pd.DataFrame(
# {"datetime": dt, "values": np.random.randint(0, 10, size=len(dt))}
# )
#
# return df
#
#
# def main():
# """A streamlit app template"""
#
# # st.sidebar.title("Tools")
# st.set_page_config(layout="wide")
# PAGES = {
# "Descriptive Analysis": DescriptiveAnalysis,
# "PreProcessing": Preprocess,
# "Predictive Analysis": PredictiveAnalysis
# }
#
# # Select page
# # Use dropdown if you prefer
# selection = st.sidebar.radio("Tools", list(PAGES.keys()))
# sidebar_caption()
# option = st.sidebar.selectbox(
# "Select A patient Record",
# ("100", "101", "102", "103", "104", "105", "106"))
#
# data = f"mit-bih-arrhythmia-database-1.0.0/{option}"
#
# record = wfdb.rdrecord(data, smooth_frames=True)
#
# page = PAGES[selection]
#
# DATA = {"record": record, }
#
# with st.spinner(f"Loading Page {selection} ..."):
#
#
#
# page = page(DATA)
# page()
#
#
# if __name__ == "__main__":
# main()

import streamlit as st
from page.PreProccessing import Preprocess
import torch
import os
import wfdb

import pandas as pd
from electroCardioGuard.PersonIdentification import PersonIdentification
from page.Descriptive_Analysis import DescriptiveAnalysis
from page.arrythmia_detection import ArrhythmiaAnalysis
from page.Predictive_Analysis import PredictiveAnalysis
from page.Myocardial_Infarction import CNN_LSTM, load_model, predict, encoder,MyocardialInfarction
from streamlit_extras.metric_cards import style_metric_cards

st.set_page_config(layout="wide")
# tab1, tab2 = st.tabs(["📈 Chart", "🗃 Data"])
tab1, tab2, tab3 ,tab4,tab5= st.tabs(["📈 ECG Purifier", "🗃 ECG Insights & Analysis", "📊Arrhythmia Detection","📊Mycardioc Infarction Detection", "📊Person Identification"])
record = None
# Initialize saved_signals in session state if not already present
if 'saved_signals' not in st.session_state:
st.session_state.saved_signals = []

def save_signal(option, signal):
update = False
for s in st.session_state.saved_signals:
if s["patient_id"] == option :
update = True
s["signal"] = signal
break
if not update:
t = {"patient_id": option, "signal": signal}
st.session_state.saved_signals.append(t)
return st.session_state.saved_signals

tab1, tab2, tab3 = st.tabs(["📈 Preprocessing", "🗃 Descriptive Analysis", "📊 Predictive Analysis"])
with tab1:
# select_col1, select_col2 = st.columns([0.5, 0.5])
#
# with select_col1:
# option = st.selectbox("Select A patient Record", ("100", "101", "102", "103", "104", "105", "106"))
#
# with select_col2:
# channel = st.selectbox("Select A patient Channel", (0,1))
#

data = f"mit-bih-arrhythmia-database-1.0.0/100"
# Instructions
st.write("""
Upload your ECG data files (WFDB format) for analysis.
""")

record = wfdb.rdrecord(data, smooth_frames=True)
signal=[]
# page = PAGES[selection]
# File uploader
uploaded_files = st.file_uploader("Choose ECG data files", type=["dat", "hea"], accept_multiple_files=True)

DATA = {"record": record, }
with tab1:
option = st.selectbox(
"Select A patient Record",
("100", "101", "102", "103", "104", "105", "106"))
if uploaded_files:
for uploaded_file in uploaded_files:
if uploaded_file.type == "application/octet-stream": # Check if it's a 'dat' file
dat_file = uploaded_file
hea_file = next((f for f in uploaded_files if f.name == uploaded_file.name.replace('.dat', '.hea')),
None)
if hea_file:
st.write(f"Uploaded files: {hea_file.name}, {dat_file.name}")
if hea_file.name == dat_file.name:
break
print(f"Uploaded files: {hea_file.name}, {dat_file.name}")

# Save uploaded files temporarily
with open(dat_file.name, 'wb') as f:
f.write(dat_file.read())
with open(hea_file.name, 'wb') as f:
f.write(hea_file.read())

# Read the record using wfdb
record = wfdb.rdrecord(dat_file.name.replace('.dat', ''))

data = f"mit-bih-arrhythmia-database-1.0.0/{option}"
# # Display basic information
# st.write("Record Information:")
# st.write(f"Sampling Frequency: {record.fs} Hz")
# st.write(f"Number of Signals: {record.n_sig}")
# st.write(f"Signal Length: {record.sig_len} samples")
#
# # Plot the first signal
# st.write("ECG Signal:")
# plt.figure(figsize=(10, 4))
# plt.plot(record.p_signal[:, 0])
# plt.xlabel('Sample')
# plt.ylabel('Amplitude')
# plt.title('ECG Signal')
# st.pyplot(plt)
#
# # Optionally, process and display additional information
# # For example, display the first 1000 points of the first signal
# st.write("First 1000 samples of the ECG signal:")
# st.line_chart(record.p_signal[:1000, 0])

record = wfdb.rdrecord(data, smooth_frames=True)
DATA = {"record": record }
# Clean up temporary files
os.remove(dat_file.name)
os.remove(hea_file.name)

page=Preprocess(DATA)
signal=page.content()
print(signal)
# st.header("A cat")
# st.image("https://static.streamlit.io/examples/cat.jpg", width=200)
#
# data = f"mit-bih-arrhythmia-database-1.0.0/{option}"
# record = wfdb.rdrecord(data, smooth_frames=True)
DATA = {"record": record, "channel": 0, "saved_signals": st.session_state.saved_signals}

page = Preprocess(DATA)
signal = page.content()

if st.button('Save'):
st.session_state.saved_signals = save_signal(dat_file.name.split('.')[0], signal)

rows = [[s["patient_id"]] for s in st.session_state.saved_signals]
df1 = pd.DataFrame(rows, columns=["patient_id"])
st.table(df1)

with tab2:
DATA = {"record": record, "signal":signal}
if record is None:
st.error("Please upload a record first.")
else:

DATA = {"record": record, "signal": signal,'saved_signals': st.session_state.saved_signals}
st.title("ECG Signal Analysis")
page = DescriptiveAnalysis(DATA)
page.content()

page = DescriptiveAnalysis(DATA)
page.content()
st.header("A dog")
st.image("https://static.streamlit.io/examples/dog.jpg", width=200)

with tab3:
st.header("An owl")
st.image("https://static.streamlit.io/examples/owl.jpg", width=200)
if record is None:
st.error("Please upload a record first.")
else:
DATA = {"record": record, "signal": signal, 'saved_signals': st.session_state.saved_signals}

page = ArrhythmiaAnalysis(DATA)
page.content()

with tab4:
if record is None:
st.error("Please upload a record first.")
else:
DATA = {"record": record, "signal": signal,'saved_signals': st.session_state.saved_signals}
page = MyocardialInfarction(DATA)
page.content()

with tab5:
if record is None:
st.error("Please upload a record first.")
else:
DATA = {"record": record, "signal": signal,'saved_signals': st.session_state.saved_signals}
page = PersonIdentification(DATA)
page.content()
Loading