ilsa15 commited on
Commit
960a638
Β·
verified Β·
1 Parent(s): 6015fa1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -16
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 DATA ----------
31
- user_habits = pd.read_csv(HABIT_FILE)
32
- data = pd.read_csv(DATA_FILE)
33
 
34
- # ---------- SIDEBAR: ADD HABIT ----------
35
- st.sidebar.markdown("## βž• Add Your Custom Habit")
36
- new_habit = st.sidebar.text_input("Enter new habit:")
 
37
 
38
- if st.sidebar.button("Add Habit"):
39
- if new_habit and new_habit not in user_habits["habit"].values:
40
- user_habits.loc[len(user_habits)] = [new_habit]
41
- user_habits.to_csv(HABIT_FILE, index=False)
42
- st.sidebar.success(f"Habit '{new_habit}' added!")
43
- elif new_habit:
44
- st.sidebar.warning("Habit already exists.")
 
 
 
 
 
 
 
 
 
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["habit"].tolist():
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.")