Spaces:
Running
Running
File size: 1,467 Bytes
7b0aaea b5b39b7 7b0aaea b5b39b7 7b0aaea b5b39b7 7b0aaea b5b39b7 7b0aaea b5b39b7 7b0aaea |
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 44 45 46 47 |
import streamlit as st
import requests
import pandas as pd
import matplotlib.pyplot as plt
st.title("Arrhythmia Detection")
models = {
"LSTM Multi": "lstm_multi_model.h5",
"CNN Multi": "cnn_multi_model.h5",
"PCA XGBoost Multi": "pca_xgboost_multi_model.pkl",
"LSTM Binary": "lstm_binary_model.h5",
"CNN Binary": "cnn_binary_model.h5",
"PCA XGBoost Binary": "pca_xgboost_binary_model.pkl",
}
# Model selection
model_name = st.selectbox("Select a Model", list(models.keys()))
# File uploader
uploaded_file = st.file_uploader("Upload a CSV file", type="csv")
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
# st.write("Uploaded Data:", df)
st.write("Visualized Data:")
fig, ax = plt.subplots(figsize=(10, 6))
df.plot(ax=ax)
st.pyplot(fig)
if st.button("Predict"):
model = models[model_name]
# Reset the file pointer to the beginning
uploaded_file.seek(0)
# Call the API with the file directly
response = requests.post(
f"https://fabriciojm-hadt-api.hf.space/predict?model_name={model}",
files={"filepath_csv": (uploaded_file.name, uploaded_file, "text/csv")},
)
if response.status_code == 200:
prediction = response.json()["prediction"]
st.write(f"Prediction using {model_name}:", prediction)
else:
st.error(f"Error: {response.json().get('detail', 'Unknown error')}")
|