Atomic_Habbit / app.py
superbsaeed's picture
Update app.py
23479ef verified
import streamlit as st
import matplotlib.pyplot as plt
st.set_page_config(page_title="Atomic Habits Tracker", page_icon="πŸ“Š")
st.title("πŸ“Š Atomic Habits Tracker (Neon Edition)")
# Initialize session state
if "habits" not in st.session_state:
st.session_state.habits = {}
# Add Habit
st.subheader("βž• Add New Habit")
new_habit = st.text_input("Enter habit name")
if st.button("Add Habit"):
if new_habit:
st.session_state.habits[new_habit] = 0
st.success(f"Habit '{new_habit}' added!")
else:
st.warning("Please enter a habit name.")
# Mark Habit as Done
st.subheader("βœ… Mark Habit as Done")
if st.session_state.habits:
habit_list = list(st.session_state.habits.keys())
selected_habit = st.selectbox("Select habit", habit_list)
if st.button("Mark Done"):
st.session_state.habits[selected_habit] += 1
st.success(
f"πŸ”₯ '{selected_habit}' streak: {st.session_state.habits[selected_habit]}"
)
else:
st.info("No habits available. Add one above.")
# Show Habits
st.subheader("πŸ“‹ Your Habits")
if st.session_state.habits:
for habit, count in st.session_state.habits.items():
st.write(f"πŸ‘‰ {habit} β†’ πŸ”₯ {count} streak")
else:
st.write("No habits to display.")
# πŸ“Š Neon Graph
st.subheader("πŸ“Š Streak Progress Graph")
if st.session_state.habits:
habits = list(st.session_state.habits.keys())
streaks = list(st.session_state.habits.values())
fig, ax = plt.subplots()
# Neon colors
neon_colors = ["#39FF14", "#FF073A", "#00FFFF", "#FF00FF", "#FFD700"]
ax.bar(habits, streaks, color=neon_colors[:len(habits)])
ax.set_title("Habit Streaks", fontsize=14)
ax.set_xlabel("Habits")
ax.set_ylabel("Streak Count")
# Dark background for neon effect
fig.patch.set_facecolor("#0E1117")
ax.set_facecolor("#0E1117")
# Make labels white for visibility
ax.tick_params(colors="white")
ax.xaxis.label.set_color("white")
ax.yaxis.label.set_color("white")
ax.title.set_color("white")
st.pyplot(fig)
else:
st.info("Add habits to see graph.")