Skip to content

Commit

Permalink
Merge pull request #209 from sanchitc05/sanchitc05/issue154
Browse files Browse the repository at this point in the history
[FEATURE] - Daily Affirmations Widget
  • Loading branch information
Amna-Hassan04 authored Nov 10, 2024
2 parents 5934023 + 565b165 commit 3310d2f
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 0 deletions.
144 changes: 144 additions & 0 deletions Daily-affirmation-widget/affirmation_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import streamlit as st
import random
import datetime
import time
import json
from datetime import datetime, timedelta

class AffirmationWidget:
def __init__(self):
# Dictionary of affirmations by theme
self.affirmations = {
"confidence": [
"I am capable of achieving anything I set my mind to.",
"I trust my abilities and inner wisdom.",
"I radiate confidence, self-respect, and inner harmony.",
"I am worthy of respect and acceptance.",
"My potential to succeed is infinite.",
"I choose to be confident and self-assured.",
"I am enough, just as I am."
],
"relaxation": [
"I choose to feel calm and peaceful.",
"I release all tension and embrace tranquility.",
"I am surrounded by peaceful energy.",
"My mind is calm, my body is relaxed.",
"I breathe in peace and exhale stress.",
"I deserve to rest and feel at peace.",
"Tranquility flows through me with each breath."
],
"productivity": [
"I am focused and productive in all I do.",
"I complete my tasks efficiently and effectively.",
"I use my time wisely and purposefully.",
"I am motivated and driven to achieve my goals.",
"I take action towards my dreams.",
"I am organized and accomplish my priorities.",
"My productivity increases each day."
]
}

def get_affirmation(self, theme):
"""Get a random affirmation from the selected theme"""
return random.choice(self.affirmations[theme])

def display_affirmation_widget():
st.markdown("""
<style>
.affirmation-container {
padding: 20px;
border-radius: 10px;
background-color: #f0f8ff;
margin: 10px 0;
text-align: center;
}
.affirmation-text {
font-size: 24px;
color: #2c3e50;
font-weight: bold;
margin: 20px 0;
}
.theme-selector {
margin: 20px 0;
}
.refresh-interval {
margin: 20px 0;
}
</style>
""", unsafe_allow_html=True)

st.markdown("## 🌟 Daily Affirmations")

# Initialize the widget
if 'affirmation_widget' not in st.session_state:
st.session_state.affirmation_widget = AffirmationWidget()

# Initialize last update time
if 'last_update' not in st.session_state:
st.session_state.last_update = datetime.now()

# Theme selection
theme = st.selectbox(
"Choose your affirmation theme:",
["confidence", "relaxation", "productivity"],
key="theme_selector"
)

# Refresh interval selection
refresh_interval = st.slider(
"Select refresh interval (minutes):",
min_value=1,
max_value=60,
value=5,
key="refresh_interval"
)

# Enable notifications
notifications_enabled = st.checkbox("Enable push notifications", value=False)

# Get current affirmation
if 'current_affirmation' not in st.session_state:
st.session_state.current_affirmation = st.session_state.affirmation_widget.get_affirmation(theme)

# Check if it's time to refresh
current_time = datetime.now()
time_difference = current_time - st.session_state.last_update
if time_difference.total_seconds() >= (refresh_interval * 60):
st.session_state.current_affirmation = st.session_state.affirmation_widget.get_affirmation(theme)
st.session_state.last_update = current_time

# Display affirmation
st.markdown(
f"""
<div class="affirmation-container">
<div class="affirmation-text">
"{st.session_state.current_affirmation}"
</div>
</div>
""",
unsafe_allow_html=True
)

# Manual refresh button
if st.button("↻ New Affirmation"):
st.session_state.current_affirmation = st.session_state.affirmation_widget.get_affirmation(theme)
st.session_state.last_update = current_time

# Display last update time
st.markdown(
f"<div style='text-align: center; color: #666;'>Last updated: {st.session_state.last_update.strftime('%I:%M %p')}</div>",
unsafe_allow_html=True
)

# Save preferences
if st.button("Save Preferences"):
preferences = {
"theme": theme,
"refresh_interval": refresh_interval,
"notifications_enabled": notifications_enabled
}
st.success("Preferences saved successfully!")

# To use this widget in your Streamlit app:
if __name__ == "__main__":
display_affirmation_widget()
54 changes: 54 additions & 0 deletions Daily-affirmation-widget/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Core dependencies
streamlit>=1.28.0
pandas>=2.0.0
numpy>=1.24.0

# DateTime handling
python-dateutil>=2.8.2
pytz>=2023.3

# Database
pymongo>=4.5.0

# HTTP requests and API handling
requests>=2.31.0
anthropic>=0.3.0

# UI components
streamlit-option-menu>=0.3.2
streamlit-lottie>=0.0.5

# Audio/Media handling
playsound>=1.3.0

# Security and encryption
python-dotenv>=1.0.0
cryptography>=41.0.0

# Notifications (if implementing push notifications)
firebase-admin>=6.2.0
pywebpush>=1.14.0

# Image processing
Pillow>=10.0.0

# Data visualization
plotly>=5.18.0

# Logging and monitoring
logging>=0.5.1.2

# State management
cachetools>=5.3.0

# JSON handling
jsonschema>=4.19.0

# For development and testing
pytest>=7.4.0
black>=23.9.0
flake8>=6.1.0

# Version control
setuptools>=68.0.0
wheel>=0.41.0
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from dotenv import load_dotenv
import logging
import sys
from affirmation_widget import display_affirmation_widget


# Configure logging
Expand Down Expand Up @@ -812,6 +813,9 @@ def simon_game_challenge():
def show_calm_space():
st.title("Calm Space")
st.write("Engage in a breathing exercise to calm your mind.")

st.subheader("Daily Affirmations")
display_affirmation_widget()

st.subheader("Quick Tips for Positivity")
quick_tips = [
Expand Down

0 comments on commit 3310d2f

Please sign in to comment.