Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
|
| 6 |
+
# Title and Description
|
| 7 |
+
st.title('Patient Data Dashboard')
|
| 8 |
+
st.write("""
|
| 9 |
+
This dashboard provides an overview of patient health metrics for better monitoring and decision-making.
|
| 10 |
+
""")
|
| 11 |
+
|
| 12 |
+
# Load Patient Data (Example DataFrame)
|
| 13 |
+
df = pd.read_csv('patient_data.csv')
|
| 14 |
+
|
| 15 |
+
# Sidebar for Patient Selection
|
| 16 |
+
st.sidebar.header('Select Patient')
|
| 17 |
+
patient_id = st.sidebar.selectbox('Patient ID', df['patient_id'].unique())
|
| 18 |
+
|
| 19 |
+
# Filter Data for Selected Patient
|
| 20 |
+
patient_data = df[df['patient_id'] == patient_id]
|
| 21 |
+
|
| 22 |
+
# Display Patient Profile
|
| 23 |
+
st.header('Patient Profile')
|
| 24 |
+
st.write(f"Name: {patient_data['name'].values[0]}")
|
| 25 |
+
st.write(f"Age: {patient_data['age'].values[0]}")
|
| 26 |
+
st.write(f"Gender: {patient_data['gender'].values[0]}")
|
| 27 |
+
st.write(f"Medical History: {patient_data['medical_history'].values[0]}")
|
| 28 |
+
|
| 29 |
+
# Visualize Vital Signs
|
| 30 |
+
st.header('Vital Signs Over Time')
|
| 31 |
+
fig, ax = plt.subplots()
|
| 32 |
+
ax.plot(patient_data['date'], patient_data['heart_rate'], label='Heart Rate')
|
| 33 |
+
ax.plot(patient_data['date'], patient_data['blood_pressure'], label='Blood Pressure')
|
| 34 |
+
ax.set_xlabel('Date')
|
| 35 |
+
ax.set_ylabel('Value')
|
| 36 |
+
ax.legend()
|
| 37 |
+
st.pyplot(fig)
|
| 38 |
+
|
| 39 |
+
# Interactive Plotly Chart
|
| 40 |
+
st.header('Blood Glucose Levels')
|
| 41 |
+
fig = px.line(patient_data, x='date', y='blood_glucose', title='Blood Glucose Over Time')
|
| 42 |
+
st.plotly_chart(fig)
|
| 43 |
+
|
| 44 |
+
# Alerts and Notifications
|
| 45 |
+
st.header('Alerts')
|
| 46 |
+
if patient_data['heart_rate'].values[-1] > 100:
|
| 47 |
+
st.error('High heart rate detected!')
|
| 48 |
+
if patient_data['blood_pressure'].values[-1] > 140:
|
| 49 |
+
st.error('High blood pressure detected!')
|
| 50 |
+
|
| 51 |
+
# Download Button for Patient Data
|
| 52 |
+
st.download_button(
|
| 53 |
+
label="Download Patient Data as CSV",
|
| 54 |
+
data=patient_data.to_csv().encode('utf-8'),
|
| 55 |
+
file_name=f'patient_{patient_id}_data.csv',
|
| 56 |
+
mime='text/csv',
|
| 57 |
+
)
|