Spaces:
Sleeping
Sleeping
Commit
β’
74601c9
1
Parent(s):
3df77f9
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Set page config
|
6 |
st.set_page_config(
|
@@ -10,7 +14,7 @@ st.set_page_config(
|
|
10 |
initial_sidebar_state="auto",
|
11 |
)
|
12 |
|
13 |
-
# Custom CSS for
|
14 |
st.markdown(
|
15 |
"""
|
16 |
<style>
|
@@ -23,9 +27,11 @@ st.markdown(
|
|
23 |
max-width: 600px;
|
24 |
margin: 0 auto;
|
25 |
padding: 2rem;
|
26 |
-
background
|
27 |
-
border-radius:
|
28 |
-
|
|
|
|
|
29 |
}
|
30 |
h1, h2, h3 {
|
31 |
font-weight: 600;
|
@@ -55,8 +61,10 @@ st.markdown(
|
|
55 |
.log-entry {
|
56 |
padding: 0.75rem;
|
57 |
margin-bottom: 1rem;
|
58 |
-
background
|
59 |
border-radius: 10px;
|
|
|
|
|
60 |
}
|
61 |
</style>
|
62 |
""",
|
@@ -67,10 +75,6 @@ st.markdown('<div class="container">', unsafe_allow_html=True)
|
|
67 |
st.markdown("<h1>Medication Tracker π</h1>", unsafe_allow_html=True)
|
68 |
st.markdown("<p>Track your prescription medications easily and get helpful insights.</p>", unsafe_allow_html=True)
|
69 |
|
70 |
-
# Initialize session state to store medication data
|
71 |
-
if 'medications' not in st.session_state:
|
72 |
-
st.session_state.medications = pd.DataFrame(columns=["Medication", "Dosage", "Time", "Date"])
|
73 |
-
|
74 |
# Form to log medication
|
75 |
st.markdown('<div class="log-form">', unsafe_allow_html=True)
|
76 |
st.markdown("<h2>Log Your Medication</h2>", unsafe_allow_html=True)
|
@@ -82,8 +86,7 @@ with st.form(key='log_medication'):
|
|
82 |
submit_button = st.form_submit_button(label='Log Medication')
|
83 |
|
84 |
if submit_button and medication_name and dosage:
|
85 |
-
|
86 |
-
st.session_state.medications = pd.concat([st.session_state.medications, new_entry], ignore_index=True)
|
87 |
st.success(f"Logged: {medication_name} - {dosage} at {time_of_day} on {date}")
|
88 |
|
89 |
st.markdown('</div>', unsafe_allow_html=True)
|
@@ -91,22 +94,24 @@ st.markdown('</div>', unsafe_allow_html=True)
|
|
91 |
# Display logged medications
|
92 |
st.markdown('<div class="logged-medications">', unsafe_allow_html=True)
|
93 |
st.markdown("<h2>Logged Medications</h2>", unsafe_allow_html=True)
|
94 |
-
|
|
|
95 |
st.markdown("No medications logged yet.", unsafe_allow_html=True)
|
96 |
else:
|
97 |
-
for
|
98 |
-
st.markdown(f'<div class="log-entry"><strong>{
|
99 |
|
100 |
st.markdown('</div>', unsafe_allow_html=True)
|
101 |
|
102 |
# Provide insights
|
103 |
st.markdown('<div class="insights">', unsafe_allow_html=True)
|
104 |
st.markdown("<h2>Insights</h2>", unsafe_allow_html=True)
|
105 |
-
if
|
106 |
-
|
|
|
107 |
st.markdown(f"Most frequently taken medication: {most_common_med}", unsafe_allow_html=True)
|
108 |
|
109 |
-
avg_dosage_time =
|
110 |
st.markdown(f"Most common time of day for taking medications: {avg_dosage_time}", unsafe_allow_html=True)
|
111 |
|
112 |
st.markdown("Take your medications consistently at the same time each day to maintain stable drug levels in your body.", unsafe_allow_html=True)
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
4 |
+
from database import init_db, add_medication, get_all_medications
|
5 |
+
|
6 |
+
# Initialize the database
|
7 |
+
init_db()
|
8 |
|
9 |
# Set page config
|
10 |
st.set_page_config(
|
|
|
14 |
initial_sidebar_state="auto",
|
15 |
)
|
16 |
|
17 |
+
# Custom CSS for glass style UI
|
18 |
st.markdown(
|
19 |
"""
|
20 |
<style>
|
|
|
27 |
max-width: 600px;
|
28 |
margin: 0 auto;
|
29 |
padding: 2rem;
|
30 |
+
background: rgba(255, 255, 255, 0.1);
|
31 |
+
border-radius: 16px;
|
32 |
+
backdrop-filter: blur(10px);
|
33 |
+
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
|
34 |
+
border: 1px solid rgba(255, 255, 255, 0.3);
|
35 |
}
|
36 |
h1, h2, h3 {
|
37 |
font-weight: 600;
|
|
|
61 |
.log-entry {
|
62 |
padding: 0.75rem;
|
63 |
margin-bottom: 1rem;
|
64 |
+
background: rgba(255, 255, 255, 0.6);
|
65 |
border-radius: 10px;
|
66 |
+
backdrop-filter: blur(5px);
|
67 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
68 |
}
|
69 |
</style>
|
70 |
""",
|
|
|
75 |
st.markdown("<h1>Medication Tracker π</h1>", unsafe_allow_html=True)
|
76 |
st.markdown("<p>Track your prescription medications easily and get helpful insights.</p>", unsafe_allow_html=True)
|
77 |
|
|
|
|
|
|
|
|
|
78 |
# Form to log medication
|
79 |
st.markdown('<div class="log-form">', unsafe_allow_html=True)
|
80 |
st.markdown("<h2>Log Your Medication</h2>", unsafe_allow_html=True)
|
|
|
86 |
submit_button = st.form_submit_button(label='Log Medication')
|
87 |
|
88 |
if submit_button and medication_name and dosage:
|
89 |
+
add_medication(medication_name, dosage, time_of_day, date)
|
|
|
90 |
st.success(f"Logged: {medication_name} - {dosage} at {time_of_day} on {date}")
|
91 |
|
92 |
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
94 |
# Display logged medications
|
95 |
st.markdown('<div class="logged-medications">', unsafe_allow_html=True)
|
96 |
st.markdown("<h2>Logged Medications</h2>", unsafe_allow_html=True)
|
97 |
+
medications = get_all_medications()
|
98 |
+
if not medications:
|
99 |
st.markdown("No medications logged yet.", unsafe_allow_html=True)
|
100 |
else:
|
101 |
+
for med in medications:
|
102 |
+
st.markdown(f'<div class="log-entry"><strong>{med[1]}</strong><br>Dosage: {med[2]}<br>Time: {med[3]}<br>Date: {med[4]}</div>', unsafe_allow_html=True)
|
103 |
|
104 |
st.markdown('</div>', unsafe_allow_html=True)
|
105 |
|
106 |
# Provide insights
|
107 |
st.markdown('<div class="insights">', unsafe_allow_html=True)
|
108 |
st.markdown("<h2>Insights</h2>", unsafe_allow_html=True)
|
109 |
+
if medications:
|
110 |
+
df = pd.DataFrame(medications, columns=["ID", "Medication", "Dosage", "Time", "Date"])
|
111 |
+
most_common_med = df['Medication'].mode()[0]
|
112 |
st.markdown(f"Most frequently taken medication: {most_common_med}", unsafe_allow_html=True)
|
113 |
|
114 |
+
avg_dosage_time = df.groupby('Time').size().idxmax()
|
115 |
st.markdown(f"Most common time of day for taking medications: {avg_dosage_time}", unsafe_allow_html=True)
|
116 |
|
117 |
st.markdown("Take your medications consistently at the same time each day to maintain stable drug levels in your body.", unsafe_allow_html=True)
|