Chris8055 commited on
Commit
aed5584
·
verified ·
1 Parent(s): 4a25e68

Create app.py

Browse files

dfgdgdfgfdgfdgfd

Files changed (1) hide show
  1. app.py +120 -0
app.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from datetime import datetime, timedelta
3
+ import random
4
+ import logging
5
+ from huggingface_hub import InferenceClient
6
+ import os
7
+
8
+ # Initialize app configurations
9
+ st.set_page_config(page_title="Task Manager with Procrastination Alerts", page_icon="📝")
10
+ st.title("📝 Task Manager with Procrastination Alerts")
11
+
12
+ # Temporary storage for user tasks
13
+ user_tasks = {}
14
+ user_preferences = {"name": "John Doe", "email": "john@gmail.com"}
15
+
16
+ # Logging setup
17
+ logging.basicConfig(level=logging.INFO)
18
+
19
+ # Hugging Face Inference client setup
20
+ access_token = os.getenv('HF_TOKEN')
21
+ if not access_token:
22
+ st.warning("Hugging Face authentication token not found.")
23
+ client = InferenceClient(
24
+ model="NousResearch/Hermes-3-Llama-3.1-8B",
25
+ token=access_token,
26
+ timeout=60.0
27
+ )
28
+
29
+ # Helper functions
30
+ def generate_numeric_id():
31
+ return int(datetime.now().timestamp() * 1000)
32
+
33
+ def filter_tasks(section):
34
+ today = datetime.now().date()
35
+ start_of_week = today - timedelta(days=today.weekday())
36
+ end_of_week = start_of_week + timedelta(days=6)
37
+
38
+ filtered_tasks = []
39
+ for task in user_tasks.values():
40
+ task_date = datetime.strptime(task['date'], '%Y-%m-%d').date()
41
+ if section == "myDay" and task_date == today:
42
+ filtered_tasks.append(task)
43
+ elif section == "thisWeek" and start_of_week <= task_date <= end_of_week:
44
+ filtered_tasks.append(task)
45
+ else:
46
+ filtered_tasks.append(task)
47
+ return filtered_tasks
48
+
49
+ def check_deadlines():
50
+ today = datetime.now().date()
51
+ return [task for task in user_tasks.values() if today <= datetime.strptime(task['date'], '%Y-%m-%d').date() <= today + timedelta(days=2)]
52
+
53
+ def alert_user(upcoming_tasks):
54
+ procrastination_messages = []
55
+ for task in upcoming_tasks:
56
+ prompt = (
57
+ f"You are my task manager who will prevent me from completing tasks. "
58
+ f"Please make me procrastinate on '{task['text']}' due on {task['date']}."
59
+ )
60
+ try:
61
+ response = client.chat_completion(
62
+ messages=[{"role": "user", "content": prompt}],
63
+ max_tokens=200
64
+ )
65
+ procrastination_message = response.choices[0].message.content
66
+ except:
67
+ logging.warning("Failed to connect to chat client.")
68
+ procrastination_message = "Unable to retrieve response."
69
+ procrastination_messages.append(procrastination_message)
70
+ return procrastination_messages
71
+
72
+ # Streamlit UI
73
+ st.sidebar.title("Task Filters")
74
+ section = st.sidebar.radio("View Tasks", ["myDay", "thisWeek", "all"])
75
+
76
+ if "user_tasks" not in st.session_state:
77
+ st.session_state.user_tasks = {}
78
+
79
+ # Task Input Form
80
+ st.subheader("Add a New Task")
81
+ with st.form("add_task_form"):
82
+ task_text = st.text_input("Task Description")
83
+ due_date = st.date_input("Due Date")
84
+ if st.form_submit_button("Add Task"):
85
+ task_id = generate_numeric_id()
86
+ st.session_state.user_tasks[task_id] = {
87
+ "id": task_id,
88
+ "text": task_text,
89
+ "date": due_date.strftime('%Y-%m-%d'),
90
+ "completed": False
91
+ }
92
+ st.success("Task added successfully.")
93
+
94
+ # Display Tasks
95
+ st.subheader("Your Tasks")
96
+ tasks_to_display = filter_tasks(section)
97
+ for task in tasks_to_display:
98
+ col1, col2, col3 = st.columns([5, 1, 1])
99
+ col1.text(f"{task['text']} (Due: {task['date']})")
100
+ if col2.button("Toggle Complete", key=f"toggle_{task['id']}"):
101
+ task["completed"] = not task["completed"]
102
+ st.success(f"Task marked as {'completed' if task['completed'] else 'incomplete'}.")
103
+ if col3.button("Delete Task", key=f"delete_{task['id']}"):
104
+ del st.session_state.user_tasks[task["id"]]
105
+ st.success("Task deleted.")
106
+
107
+ # Procrastination Alerts
108
+ st.subheader("Upcoming Deadlines")
109
+ upcoming_tasks = check_deadlines()
110
+ if upcoming_tasks:
111
+ if st.button("Get Procrastination Message"):
112
+ messages = alert_user(upcoming_tasks)
113
+ st.info(random.choice(messages))
114
+ else:
115
+ st.info("No tasks with urgent deadlines.")
116
+
117
+ # Clear All Tasks
118
+ if st.button("Delete All Tasks"):
119
+ st.session_state.user_tasks.clear()
120
+ st.success("All tasks deleted.")