Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import datetime
|
5 |
+
import random
|
6 |
+
|
7 |
+
# Application Title
|
8 |
+
st.title("Mood Tracker App")
|
9 |
+
|
10 |
+
# Sidebar for Navigation
|
11 |
+
st.sidebar.title("Navigation")
|
12 |
+
page = st.sidebar.radio("Go to", ["Home", "Track Mood", "Mood Trends"])
|
13 |
+
|
14 |
+
# Session State Initialization
|
15 |
+
if "mood_data" not in st.session_state:
|
16 |
+
st.session_state["mood_data"] = pd.DataFrame(columns=["Date", "Mood"])
|
17 |
+
|
18 |
+
if page == "Home":
|
19 |
+
# Home Page
|
20 |
+
st.header("Welcome to the Mood Tracker App")
|
21 |
+
st.markdown(
|
22 |
+
"""
|
23 |
+
This app helps you track your mood over time. Record how you feel daily, visualize trends, and get personalized motivational quotes.
|
24 |
+
|
25 |
+
**How to Use**:
|
26 |
+
- Go to **Track Mood** to log your daily mood.
|
27 |
+
- Check **Mood Trends** to see how your mood evolves over time.
|
28 |
+
|
29 |
+
Let's build a habit of emotional awareness!
|
30 |
+
"""
|
31 |
+
)
|
32 |
+
|
33 |
+
elif page == "Track Mood":
|
34 |
+
# Track Mood Page
|
35 |
+
st.header("Track Your Mood")
|
36 |
+
|
37 |
+
# Mood Input
|
38 |
+
mood = st.radio("How are you feeling today?", ["Happy", "Sad", "Anxious", "Neutral", "Excited", "Angry"])
|
39 |
+
submit = st.button("Submit")
|
40 |
+
|
41 |
+
# Save Mood
|
42 |
+
if submit:
|
43 |
+
today = datetime.date.today()
|
44 |
+
new_entry = {"Date": today, "Mood": mood}
|
45 |
+
if today not in st.session_state["mood_data"]["Date"].values:
|
46 |
+
st.session_state["mood_data"] = pd.concat(
|
47 |
+
[st.session_state["mood_data"], pd.DataFrame([new_entry])], ignore_index=True
|
48 |
+
)
|
49 |
+
st.success(f"Mood for {today} saved successfully!")
|
50 |
+
else:
|
51 |
+
st.warning(f"Mood for {today} is already recorded. Edit it in your data table.")
|
52 |
+
|
53 |
+
elif page == "Mood Trends":
|
54 |
+
# Mood Trends Page
|
55 |
+
st.header("Mood Trends")
|
56 |
+
|
57 |
+
# Check if there's data
|
58 |
+
if st.session_state["mood_data"].empty:
|
59 |
+
st.warning("No mood data found. Please log your mood in the Track Mood section.")
|
60 |
+
else:
|
61 |
+
# Display Data
|
62 |
+
st.subheader("Your Mood Records")
|
63 |
+
st.write(st.session_state["mood_data"])
|
64 |
+
|
65 |
+
# Prepare Data for Plotting
|
66 |
+
mood_counts = st.session_state["mood_data"].groupby("Mood").size()
|
67 |
+
|
68 |
+
# Plot Mood Trends
|
69 |
+
fig, ax = plt.subplots()
|
70 |
+
st.session_state["mood_data"].sort_values("Date", inplace=True)
|
71 |
+
st.session_state["mood_data"].plot(
|
72 |
+
x="Date", y="Mood", kind="line", marker="o", ax=ax, legend=False
|
73 |
+
)
|
74 |
+
ax.set_ylabel("Mood")
|
75 |
+
ax.set_title("Mood Trends Over Time")
|
76 |
+
st.pyplot(fig)
|
77 |
+
|
78 |
+
# Motivational Quotes
|
79 |
+
st.subheader("Motivational Quote of the Day")
|
80 |
+
quotes = [
|
81 |
+
"Keep your face to the sunshine and you cannot see a shadow. - Helen Keller",
|
82 |
+
"The best way to predict the future is to create it. - Peter Drucker",
|
83 |
+
"Happiness is not something ready made. It comes from your own actions. - Dalai Lama",
|
84 |
+
"Every day may not be good, but there's something good in every day.",
|
85 |
+
"Believe you can and you're halfway there. - Theodore Roosevelt",
|
86 |
+
]
|
87 |
+
st.write(random.choice(quotes))
|