From 825fdff65cfeebdaae14db866eb7e303aa8a8406 Mon Sep 17 00:00:00 2001 From: "Simon S. Viloria" Date: Tue, 3 Oct 2023 20:39:04 +0200 Subject: [PATCH] bug fixes --- Dockerfile | 6 ------ app/main.py | 25 ++++++++++++++----------- app/requirements.txt | 7 ++++--- requirements.txt | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0fee700..d8fb3d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,5 @@ FROM python:3.8-buster -# Make sure pip and git are installed -RUN apt-get update && apt-get install -y python3-pip && apt-get install -y git - -# Upgrade pip -RUN pip3 install --upgrade pip - # Add the project folder to the container ADD app /app diff --git a/app/main.py b/app/main.py index 920abee..0e416a9 100644 --- a/app/main.py +++ b/app/main.py @@ -42,7 +42,7 @@ #---------------------------------# # Data preprocessing and Model building -@st.cache(allow_output_mutation=True) +@st.cache_data def read_ecg_preprocessing(uploaded_ecg): FS = 300 @@ -67,14 +67,14 @@ def read_ecg_preprocessing(uploaded_ecg): model_path = 'models/weights-best.hdf5' classes = ['Normal','Atrial Fibrillation','Other','Noise'] -@st.cache(allow_output_mutation=False,ttl=24*60*60) +@st.cache_resource def get_model(model_path): model = load_model(f'{model_path}') return model -@st.cache(allow_output_mutation=True,show_spinner=False) -def get_prediction(data,model): - prob = model(data) +@st.cache_resource +def get_prediction(data,_model): + prob = _model(data) ann = np.argmax(prob) #true_target = #print(true_target,ann) @@ -84,7 +84,7 @@ def get_prediction(data,model): # Visualization -------------------------------------- -@st.cache(allow_output_mutation=True,show_spinner=False) +@st.cache_resource def visualize_ecg(ecg,FS): fig = plot_ecg(uploaded_ecg=ecg, FS=FS) return fig @@ -181,15 +181,18 @@ def visualize_ecg(ecg,FS): st.subheader('2. Model Predictions') with st.spinner(text="Running Model..."): pred,conf = get_prediction(ecg,model) - mkd_pred_table = """ - | Rhythm Type | Confidence | - | --- | --- | - """ + "\n".join([f"| {classes[i]} | {conf[0][i]*100:.2f}% |" for i in range(len(classes))]) + mkd_pred_table = [ + "| Rhythm Type | Confidence |", + "| --- | --- |" + ] + for i in range(len(classes)): + mkd_pred_table.append(f"| {classes[i]} | {conf[0,i]*100:3.1f}% |") + mkd_pred_table = "\n".join(mkd_pred_table) st.write("ECG classified as **{}**".format(pred)) pred_confidence = conf[0,np.argmax(conf)]*100 st.write("Confidence of the prediction: **{:3.1f}%**".format(pred_confidence)) st.write(f"**Likelihoods:**") - st.markdown(mkd_pred_table, unsafe_allow_html=False) + st.markdown(mkd_pred_table) # st.line_chart(np.concatenate(ecg).ravel().tolist()) diff --git a/app/requirements.txt b/app/requirements.txt index 8afee7d..a52eaf3 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,6 +1,7 @@ -# tensorflow>=2.5.1 -keras==2.4 +tensorflow>=2.5.1 +keras streamlit +scipy matplotlib git+https://github.com/simonsanvil/subplotted.git --e . +-e . \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3c3983e..e3b0a72 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ awscli flake8 python-dotenv>=0.5.1 tensorflow>=2.5.1 -keras==2.4 +keras streamlit matplotlib git+https://github.com/simonsanvil/subplotted.git \ No newline at end of file