Spaces:
Sleeping
Sleeping
File size: 2,628 Bytes
344f8b9 |
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import datetime as dt
# Initialize session state for storing mood logs
if "mood_data" not in st.session_state:
st.session_state.mood_data = pd.DataFrame(columns=["Date", "Mood", "Activity", "Notes"])
# App title and description
st.title("Mood Tracker")
st.write("A simple app to log and track your mood over time.")
# Sidebar for mood input
st.sidebar.header("Log Your Mood")
mood = st.sidebar.selectbox("How are you feeling today?", ["Happy", "Neutral", "Sad", "Anxious", "Excited", "Angry"])
activity = st.sidebar.text_input("What activity were you doing?")
notes = st.sidebar.text_area("Add any notes (optional):")
log_button = st.sidebar.button("Log Mood")
# Log the mood
if log_button:
new_entry = pd.DataFrame({
"Date": [dt.datetime.now()],
"Mood": [mood],
"Activity": [activity],
"Notes": [notes]
})
st.session_state.mood_data = pd.concat([st.session_state.mood_data, new_entry], ignore_index=True)
st.success("Mood logged successfully!")
# Display mood data
st.header("Mood History")
if not st.session_state.mood_data.empty:
st.dataframe(st.session_state.mood_data.sort_values(by="Date", ascending=False))
else:
st.write("No mood data logged yet. Use the sidebar to add entries.")
# Visualize mood trends
st.header("Mood Trends")
if not st.session_state.mood_data.empty:
# Convert date column to datetime for grouping
st.session_state.mood_data["Date"] = pd.to_datetime(st.session_state.mood_data["Date"])
mood_counts = st.session_state.mood_data.groupby(["Mood"]).size()
# Bar chart for mood distribution
fig, ax = plt.subplots()
mood_counts.plot(kind="bar", color="skyblue", ax=ax)
ax.set_title("Mood Distribution")
ax.set_ylabel("Count")
ax.set_xlabel("Mood")
st.pyplot(fig)
# Trend over time
mood_over_time = st.session_state.mood_data.groupby(st.session_state.mood_data["Date"].dt.date).size()
fig, ax = plt.subplots()
mood_over_time.plot(ax=ax, marker="o", color="orange")
ax.set_title("Mood Over Time")
ax.set_ylabel("Entries")
ax.set_xlabel("Date")
st.pyplot(fig)
else:
st.write("No data available for visualizations.")
# Resources for mental health
st.header("Mental Health Resources")
st.write("Here are some tips and resources to help improve your mental health:")
st.markdown("- Practice mindfulness and deep breathing.")
st.markdown("- Stay physically active.")
st.markdown("- Talk to a trusted friend or counselor.")
st.markdown("- [Find a therapist](https://www.psychologytoday.com)")
|