Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ def init_file(path, cols):
|
|
| 18 |
if not os.path.exists(path):
|
| 19 |
pd.DataFrame(columns=cols).to_csv(path, index=False)
|
| 20 |
|
| 21 |
-
init_file(HABIT_FILE, ["habit"])
|
| 22 |
init_file(DATA_FILE, ["username", "date", "mood", "mood_note", "habit", "completed"])
|
| 23 |
|
| 24 |
# ---------- USER LOGIN ----------
|
|
@@ -27,21 +27,31 @@ if not username:
|
|
| 27 |
st.warning("Please enter your name to continue.")
|
| 28 |
st.stop()
|
| 29 |
|
| 30 |
-
# ---------- LOAD
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
# ----------
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# ---------- MOOD & NOTE ----------
|
| 47 |
st.markdown(f"### Hello, {username}! Today is **{TODAY}**")
|
|
@@ -51,7 +61,7 @@ mood_note = st.text_area("π Describe how you're feeling today (optional):")
|
|
| 51 |
# ---------- HABIT CHECKLIST ----------
|
| 52 |
st.markdown("### β
Select completed habits:")
|
| 53 |
completed_today = []
|
| 54 |
-
for habit in user_habits
|
| 55 |
if st.checkbox(habit):
|
| 56 |
completed_today.append(habit)
|
| 57 |
|
|
@@ -126,4 +136,3 @@ if os.path.exists(DATA_FILE):
|
|
| 126 |
st.dataframe(df.sort_values(by="date", ascending=False), use_container_width=True)
|
| 127 |
else:
|
| 128 |
st.info("Start tracking to view analytics.")
|
| 129 |
-
|
|
|
|
| 18 |
if not os.path.exists(path):
|
| 19 |
pd.DataFrame(columns=cols).to_csv(path, index=False)
|
| 20 |
|
| 21 |
+
init_file(HABIT_FILE, ["username", "habit"])
|
| 22 |
init_file(DATA_FILE, ["username", "date", "mood", "mood_note", "habit", "completed"])
|
| 23 |
|
| 24 |
# ---------- USER LOGIN ----------
|
|
|
|
| 27 |
st.warning("Please enter your name to continue.")
|
| 28 |
st.stop()
|
| 29 |
|
| 30 |
+
# ---------- LOAD USER HABITS ----------
|
| 31 |
+
user_habits_df = pd.read_csv(HABIT_FILE)
|
| 32 |
+
user_habits = user_habits_df[user_habits_df["username"] == username]["habit"].tolist()
|
| 33 |
|
| 34 |
+
# ---------- FIRST-TIME HABIT SETUP ----------
|
| 35 |
+
if not user_habits:
|
| 36 |
+
st.markdown("### π οΈ Setup Your Habits")
|
| 37 |
+
st.info("Please enter at least 3 habits you want to track:")
|
| 38 |
|
| 39 |
+
habit_inputs = []
|
| 40 |
+
for i in range(1, 6):
|
| 41 |
+
habit = st.text_input(f"Habit {i} (optional):")
|
| 42 |
+
if habit:
|
| 43 |
+
habit_inputs.append(habit)
|
| 44 |
+
|
| 45 |
+
if st.button("β
Save My Habits"):
|
| 46 |
+
if len(habit_inputs) < 3:
|
| 47 |
+
st.warning("Please enter at least 3 habits.")
|
| 48 |
+
else:
|
| 49 |
+
new_df = pd.DataFrame([{"username": username, "habit": h} for h in habit_inputs])
|
| 50 |
+
new_df.to_csv(HABIT_FILE, mode="a", index=False, header=False)
|
| 51 |
+
st.success("β
Your habits are saved! Please reload the app.")
|
| 52 |
+
st.stop()
|
| 53 |
+
else:
|
| 54 |
+
st.stop()
|
| 55 |
|
| 56 |
# ---------- MOOD & NOTE ----------
|
| 57 |
st.markdown(f"### Hello, {username}! Today is **{TODAY}**")
|
|
|
|
| 61 |
# ---------- HABIT CHECKLIST ----------
|
| 62 |
st.markdown("### β
Select completed habits:")
|
| 63 |
completed_today = []
|
| 64 |
+
for habit in user_habits:
|
| 65 |
if st.checkbox(habit):
|
| 66 |
completed_today.append(habit)
|
| 67 |
|
|
|
|
| 136 |
st.dataframe(df.sort_values(by="date", ascending=False), use_container_width=True)
|
| 137 |
else:
|
| 138 |
st.info("Start tracking to view analytics.")
|
|
|