Chris8055 commited on
Commit
e9e3bc7
·
verified ·
1 Parent(s): c7027d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -19
app.py CHANGED
@@ -48,11 +48,17 @@ def check_deadlines():
48
 
49
  def alert_user(upcoming_tasks):
50
  procrastination_messages = []
 
 
 
 
 
 
 
 
 
51
  for task in upcoming_tasks:
52
- prompt = (
53
- f"You are my task manager who will prevent me from completing tasks. "
54
- f"Please make me procrastinate on '{task['text']}' due on {task['date']}."
55
- )
56
  try:
57
  response = client.chat_completion(
58
  messages=[{"role": "user", "content": prompt}],
@@ -71,6 +77,21 @@ if "logged_in" not in st.session_state:
71
  if "user_tasks" not in st.session_state:
72
  st.session_state.user_tasks = {}
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  # Login Page
75
  def login():
76
  st.subheader("Login")
@@ -122,25 +143,14 @@ if st.session_state.logged_in:
122
  # Display Tasks
123
  st.subheader("Your Tasks")
124
  tasks_to_display = filter_tasks(section)
125
- for task in tasks_to_display:
126
- col1, col2, col3 = st.columns([5, 1, 1])
127
- col1.text(f"{task['text']} (Due: {task['date']})")
128
- if col2.button("Toggle Complete", key=f"toggle_{task['id']}"):
129
- task["completed"] = not task["completed"]
130
- st.success(f"Task marked as {'completed' if task['completed'] else 'incomplete'}.")
131
- if col3.button("Delete Task", key=f"delete_{task['id']}"):
132
- del st.session_state.user_tasks[task["id"]]
133
- st.success("Task deleted.")
134
 
135
  # Procrastination Alerts
136
  st.subheader("Upcoming Deadlines")
137
  upcoming_tasks = check_deadlines()
138
- if upcoming_tasks:
139
- if st.button("Get Procrastination Message"):
140
- messages = alert_user(upcoming_tasks)
141
- st.info(random.choice(messages))
142
- else:
143
- st.info("No tasks with urgent deadlines.")
144
 
145
  # Clear All Tasks
146
  if st.button("Delete All Tasks"):
 
48
 
49
  def alert_user(upcoming_tasks):
50
  procrastination_messages = []
51
+ # Sample procrastination prompts
52
+ procrastination_prompts = [
53
+ "Take a break! You can do '{task}' later.",
54
+ "Why not relax for a while? '{task}' isn't going anywhere.",
55
+ "You've earned a rest! Save '{task}' for later.",
56
+ "Maybe watch a quick video before starting '{task}'?",
57
+ "A quick snack could be just what you need before tackling '{task}'.",
58
+ ]
59
+
60
  for task in upcoming_tasks:
61
+ prompt = random.choice(procrastination_prompts).format(task=task['text'])
 
 
 
62
  try:
63
  response = client.chat_completion(
64
  messages=[{"role": "user", "content": prompt}],
 
77
  if "user_tasks" not in st.session_state:
78
  st.session_state.user_tasks = {}
79
 
80
+ # Display tasks function
81
+ def display_tasks(tasks):
82
+ for task in tasks:
83
+ col1, col2, col3 = st.columns([5, 1, 1])
84
+ with col1:
85
+ st.markdown(f"**{task['text']}** - Due: {task['date']} - {'Completed' if task['completed'] else 'Pending'}")
86
+ with col2:
87
+ if st.button("Toggle Complete", key=f"toggle_{task['id']}"):
88
+ task["completed"] = not task["completed"]
89
+ st.experimental_rerun()
90
+ with col3:
91
+ if st.button("Delete", key=f"delete_{task['id']}"):
92
+ del st.session_state.user_tasks[task["id"]]
93
+ st.experimental_rerun()
94
+
95
  # Login Page
96
  def login():
97
  st.subheader("Login")
 
143
  # Display Tasks
144
  st.subheader("Your Tasks")
145
  tasks_to_display = filter_tasks(section)
146
+ display_tasks(tasks_to_display)
 
 
 
 
 
 
 
 
147
 
148
  # Procrastination Alerts
149
  st.subheader("Upcoming Deadlines")
150
  upcoming_tasks = check_deadlines()
151
+ if upcoming_tasks and st.button("Get Procrastination Message"):
152
+ messages = alert_user(upcoming_tasks)
153
+ st.info(random.choice(messages))
 
 
 
154
 
155
  # Clear All Tasks
156
  if st.button("Delete All Tasks"):