Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import datetime | |
import random | |
# Application Title | |
st.title("Mood Tracker App") | |
# Sidebar for Navigation | |
st.sidebar.title("Navigation") | |
page = st.sidebar.radio("Go to", ["Home", "Track Mood", "Mood Trends"]) | |
# Session State Initialization | |
if "mood_data" not in st.session_state: | |
st.session_state["mood_data"] = pd.DataFrame(columns=["Date", "Mood"]) | |
if page == "Home": | |
# Home Page | |
st.header("Welcome to the Mood Tracker App") | |
st.markdown( | |
""" | |
This app helps you track your mood over time. Record how you feel daily, visualize trends, and get personalized motivational quotes. | |
**How to Use**: | |
- Go to **Track Mood** to log your daily mood. | |
- Check **Mood Trends** to see how your mood evolves over time. | |
Let's build a habit of emotional awareness! | |
""" | |
) | |
elif page == "Track Mood": | |
# Track Mood Page | |
st.header("Track Your Mood") | |
# Mood Input | |
mood = st.radio("How are you feeling today?", ["Happy", "Sad", "Anxious", "Neutral", "Excited", "Angry"]) | |
submit = st.button("Submit") | |
# Save Mood | |
if submit: | |
today = datetime.date.today() | |
new_entry = {"Date": today, "Mood": mood} | |
if today not in st.session_state["mood_data"]["Date"].values: | |
st.session_state["mood_data"] = pd.concat( | |
[st.session_state["mood_data"], pd.DataFrame([new_entry])], ignore_index=True | |
) | |
st.success(f"Mood for {today} saved successfully!") | |
else: | |
st.warning(f"Mood for {today} is already recorded. Edit it in your data table.") | |
elif page == "Mood Trends": | |
# Mood Trends Page | |
st.header("Mood Trends") | |
# Check if there's data | |
if st.session_state["mood_data"].empty: | |
st.warning("No mood data found. Please log your mood in the Track Mood section.") | |
else: | |
# Display Data | |
st.subheader("Your Mood Records") | |
st.write(st.session_state["mood_data"]) | |
# Prepare Data for Plotting | |
mood_counts = st.session_state["mood_data"].groupby("Mood").size() | |
# Plot Mood Trends | |
fig, ax = plt.subplots() | |
st.session_state["mood_data"].sort_values("Date", inplace=True) | |
st.session_state["mood_data"].plot( | |
x="Date", y="Mood", kind="line", marker="o", ax=ax, legend=False | |
) | |
ax.set_ylabel("Mood") | |
ax.set_title("Mood Trends Over Time") | |
st.pyplot(fig) | |
# Motivational Quotes | |
st.subheader("Motivational Quote of the Day") | |
quotes = [ | |
"Keep your face to the sunshine and you cannot see a shadow. - Helen Keller", | |
"The best way to predict the future is to create it. - Peter Drucker", | |
"Happiness is not something ready made. It comes from your own actions. - Dalai Lama", | |
"Every day may not be good, but there's something good in every day.", | |
"Believe you can and you're halfway there. - Theodore Roosevelt", | |
] | |
st.write(random.choice(quotes)) | |