import streamlit as st import pandas as pd from datetime import datetime from database import init_db, add_medication, get_all_medications # Initialize the database init_db() # Set page config st.set_page_config( page_title="Medication Tracker", page_icon="💊", layout="centered", initial_sidebar_state="auto", ) # Custom CSS for glass style UI st.markdown( """ """, unsafe_allow_html=True ) st.markdown('
', unsafe_allow_html=True) st.markdown("

Medication Tracker 💊

", unsafe_allow_html=True) st.markdown("

Track your prescription medications easily and get helpful insights.

", unsafe_allow_html=True) # Form to log medication st.markdown('
', unsafe_allow_html=True) st.markdown("

Log Your Medication

", unsafe_allow_html=True) with st.form(key='log_medication'): medication_name = st.text_input("Medication Name", key='medication_name', placeholder="e.g., Aspirin") dosage = st.text_input("Dosage (e.g., 500 mg)", key='dosage', placeholder="e.g., 500 mg") time_of_day = st.selectbox("Time of Day", ["Morning", "Afternoon", "Evening", "Night"], key='time_of_day') date = st.date_input("Date", datetime.today(), key='date') submit_button = st.form_submit_button(label='Log Medication') if submit_button and medication_name and dosage: add_medication(medication_name, dosage, time_of_day, date) st.success(f"Logged: {medication_name} - {dosage} at {time_of_day} on {date}") st.markdown('
', unsafe_allow_html=True) # Display logged medications st.markdown('
', unsafe_allow_html=True) st.markdown("

Logged Medications

", unsafe_allow_html=True) medications = get_all_medications() if not medications: st.markdown("No medications logged yet.", unsafe_allow_html=True) else: for med in medications: st.markdown(f'
{med[1]}
Dosage: {med[2]}
Time: {med[3]}
Date: {med[4]}
', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) # Provide insights st.markdown('
', unsafe_allow_html=True) st.markdown("

Insights

", unsafe_allow_html=True) if medications: df = pd.DataFrame(medications, columns=["ID", "Medication", "Dosage", "Time", "Date"]) most_common_med = df['Medication'].mode()[0] st.markdown(f"Most frequently taken medication: {most_common_med}", unsafe_allow_html=True) avg_dosage_time = df.groupby('Time').size().idxmax() st.markdown(f"Most common time of day for taking medications: {avg_dosage_time}", unsafe_allow_html=True) st.markdown("Take your medications consistently at the same time each day to maintain stable drug levels in your body.", unsafe_allow_html=True) st.markdown("If you have multiple medications, consult your healthcare provider to ensure there are no adverse interactions.", unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) # Footer st.markdown("
", unsafe_allow_html=True) st.markdown("

Disclaimer: This app is for tracking purposes only. Always consult with your healthcare provider for medical advice.

", unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True)