SNA-AI commited on
Commit
3980fcb
·
verified ·
1 Parent(s): 207d922

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -37
app.py CHANGED
@@ -6,30 +6,17 @@ import matplotlib.pyplot as plt
6
 
7
  DATA_FILE = "habits.csv"
8
 
9
- # ---------- Page Setup ----------
10
- st.set_page_config(
11
- page_title="Habit Tracker",
12
- layout="centered"
13
- )
14
 
15
- # ---------- UI Styling ----------
16
  st.markdown("""
17
  <style>
18
  .block-container {
19
  padding-top: 2rem;
20
- padding-bottom: 2rem;
21
  }
22
 
23
- h1 {
24
- text-align: center;
25
- color: #0f172a;
26
- font-size: 36px;
27
- }
28
-
29
- .subtext {
30
- text-align: center;
31
- color: #64748b;
32
- margin-bottom: 20px;
33
  }
34
 
35
  .card {
@@ -37,7 +24,7 @@ h1 {
37
  padding: 14px;
38
  border-radius: 12px;
39
  border-left: 5px solid #38bdf8;
40
- box-shadow: 0 2px 8px rgba(0,0,0,0.06);
41
  margin-bottom: 10px;
42
  }
43
 
@@ -51,7 +38,6 @@ h1 {
51
  color: white;
52
  border-radius: 8px;
53
  border: none;
54
- padding: 6px 12px;
55
  }
56
 
57
  .stButton > button:hover {
@@ -60,7 +46,7 @@ h1 {
60
  </style>
61
  """, unsafe_allow_html=True)
62
 
63
- # ---------- Data ----------
64
  def load_data():
65
  if os.path.exists(DATA_FILE):
66
  return pd.read_csv(DATA_FILE)
@@ -74,15 +60,14 @@ if "habits" not in st.session_state:
74
 
75
  df = st.session_state.habits
76
 
77
- # ---------- Title ----------
78
  st.title("Habit Tracker")
79
- st.markdown("<div class='subtext'>Track your daily habits and build consistency</div>", unsafe_allow_html=True)
80
 
81
- # ---------- Add Habit ----------
82
  st.subheader("Add Habit")
83
 
84
  col1, col2 = st.columns([4, 1])
85
-
86
  with col1:
87
  new_habit = st.text_input("Enter habit", label_visibility="collapsed")
88
 
@@ -96,27 +81,26 @@ with col2:
96
  )
97
  st.session_state.habits = df
98
  save_data(df)
99
- st.success("Habit added")
100
  else:
101
  st.warning("Already exists")
102
- else:
103
- st.warning("Enter a habit name")
104
 
105
- # ---------- Habits ----------
106
  st.subheader("Your Habits")
107
 
108
  today = datetime.now().date()
109
 
110
  if df.empty:
111
- st.info("No habits added yet")
112
  else:
113
  for i, row in df.iterrows():
 
114
  col1, col2, col3 = st.columns([5, 1, 1])
115
 
116
  with col1:
117
  st.markdown(f"""
118
  <div class="card">
119
- <div style="font-size:16px; font-weight:600;">
120
  {row['Habit']}
121
  </div>
122
  <div class="streak">
@@ -153,17 +137,12 @@ else:
153
  save_data(df)
154
  st.rerun()
155
 
156
- # ---------- Chart ----------
157
  st.subheader("Progress")
158
 
159
  if not df.empty:
160
  fig, ax = plt.subplots()
161
  ax.bar(df["Habit"], df["Streak"], color="#38bdf8")
162
  ax.set_ylabel("Streak")
163
- ax.set_xlabel("Habit")
164
  plt.xticks(rotation=20)
165
- st.pyplot(fig)
166
-
167
- # ---------- Footer ----------
168
- st.markdown("---")
169
- st.write("Consistency builds results.")
 
6
 
7
  DATA_FILE = "habits.csv"
8
 
9
+ st.set_page_config(page_title="Habit Tracker", layout="centered")
 
 
 
 
10
 
11
+ # ---------- SAFE VISIBILITY CSS ----------
12
  st.markdown("""
13
  <style>
14
  .block-container {
15
  padding-top: 2rem;
 
16
  }
17
 
18
+ h1, h2, h3, p, div {
19
+ color: #0f172a !important;
 
 
 
 
 
 
 
 
20
  }
21
 
22
  .card {
 
24
  padding: 14px;
25
  border-radius: 12px;
26
  border-left: 5px solid #38bdf8;
27
+ box-shadow: 0 2px 8px rgba(0,0,0,0.08);
28
  margin-bottom: 10px;
29
  }
30
 
 
38
  color: white;
39
  border-radius: 8px;
40
  border: none;
 
41
  }
42
 
43
  .stButton > button:hover {
 
46
  </style>
47
  """, unsafe_allow_html=True)
48
 
49
+ # ---------- DATA ----------
50
  def load_data():
51
  if os.path.exists(DATA_FILE):
52
  return pd.read_csv(DATA_FILE)
 
60
 
61
  df = st.session_state.habits
62
 
63
+ # ---------- TITLE ----------
64
  st.title("Habit Tracker")
65
+ st.write("Track habits and build consistency")
66
 
67
+ # ---------- ADD ----------
68
  st.subheader("Add Habit")
69
 
70
  col1, col2 = st.columns([4, 1])
 
71
  with col1:
72
  new_habit = st.text_input("Enter habit", label_visibility="collapsed")
73
 
 
81
  )
82
  st.session_state.habits = df
83
  save_data(df)
84
+ st.success("Added")
85
  else:
86
  st.warning("Already exists")
 
 
87
 
88
+ # ---------- HABITS ----------
89
  st.subheader("Your Habits")
90
 
91
  today = datetime.now().date()
92
 
93
  if df.empty:
94
+ st.info("No habits yet")
95
  else:
96
  for i, row in df.iterrows():
97
+
98
  col1, col2, col3 = st.columns([5, 1, 1])
99
 
100
  with col1:
101
  st.markdown(f"""
102
  <div class="card">
103
+ <div style="font-size:16px; font-weight:600; color:#0f172a;">
104
  {row['Habit']}
105
  </div>
106
  <div class="streak">
 
137
  save_data(df)
138
  st.rerun()
139
 
140
+ # ---------- GRAPH ----------
141
  st.subheader("Progress")
142
 
143
  if not df.empty:
144
  fig, ax = plt.subplots()
145
  ax.bar(df["Habit"], df["Streak"], color="#38bdf8")
146
  ax.set_ylabel("Streak")
 
147
  plt.xticks(rotation=20)
148
+ st.pyplot(fig)