Kikulika commited on
Commit
bbf093c
·
verified ·
1 Parent(s): 9ffa4d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -72
app.py CHANGED
@@ -10,9 +10,16 @@ STATUS_COLORS = {
10
  "Done": "#e6ffe6"
11
  }
12
 
13
- TASKS_FILE = "/data/tasks.csv" # Hugging Face Spaces persistent storage
 
14
  ASSIGNEE_FILE = "Assignee.txt"
15
 
 
 
 
 
 
 
16
  def load_tasks():
17
  """Load tasks from CSV file"""
18
  try:
@@ -24,7 +31,7 @@ def load_tasks():
24
  return create_empty_df()
25
 
26
  def save_tasks():
27
- """Save tasks to CSV file with proper permissions"""
28
  try:
29
  st.session_state.tasks.to_csv(TASKS_FILE, index=False)
30
  except PermissionError:
@@ -32,15 +39,6 @@ def save_tasks():
32
  except Exception as e:
33
  st.error(f"Error saving tasks: {str(e)}")
34
 
35
- def create_empty_df():
36
- return pd.DataFrame(columns=[
37
- 'Title', 'Description', 'Assignee', 'Status', 'Due Date'
38
- ])
39
-
40
- def save_tasks():
41
- """Save tasks to CSV file"""
42
- st.session_state.tasks.to_csv(TASKS_FILE, index=False)
43
-
44
  def load_assignees():
45
  """Load assignees from text file"""
46
  assignees = []
@@ -53,40 +51,12 @@ def load_assignees():
53
  if ' ' in name_part:
54
  assignees.append(name_part)
55
  except FileNotFoundError:
56
- st.error("Assignee.txt file not found!")
 
 
57
  return assignees
58
 
59
- # Initialize session state ONLY ONCE
60
- if 'tasks' not in st.session_state:
61
- st.session_state.tasks = load_tasks() # This line was duplicated before
62
-
63
- # Load assignees once and reuse
64
- assignee_list = load_assignees()
65
-
66
- # Sidebar for new tasks
67
- with st.sidebar:
68
- st.header("➕ Add New Task")
69
- title = st.text_input("Task Title")
70
- description = st.text_area("Description")
71
- assignee = st.selectbox("Assignee", load_assignees())
72
- status = st.selectbox("Status", ["To Do", "In Progress", "Done"])
73
- due_date = st.date_input("Due Date")
74
-
75
- if st.button("Add Task"):
76
- new_task = {
77
- 'Title': title,
78
- 'Description': description,
79
- 'Assignee': assignee,
80
- 'Status': status,
81
- 'Due Date': due_date
82
- }
83
- st.session_state.tasks = pd.concat([
84
- st.session_state.tasks,
85
- pd.DataFrame([new_task])
86
- ], ignore_index=True)
87
- save_tasks()
88
-
89
- # Function to create styled task cards (same as before)
90
  def task_card(title, description, assignee, status, due_date):
91
  color = STATUS_COLORS.get(status, "#ffffff")
92
  card = f"""
@@ -101,39 +71,77 @@ def task_card(title, description, assignee, status, due_date):
101
  <p><strong>Assignee:</strong> {assignee}</p>
102
  <p><strong>Due Date:</strong> {due_date}</p>
103
  <p><strong>Description:</strong> {description}</p>
104
- <div style="margin-top: 15px;">
 
105
  """
106
  return card
107
 
108
- # Main display
 
 
 
 
 
 
 
109
  st.title("Company Task Board 🗒️")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  st.divider()
111
 
112
  # Display tasks in cards
113
- for idx, task in st.session_state.tasks.iterrows():
114
- card = task_card(
115
- task['Title'],
116
- task['Description'],
117
- task['Assignee'],
118
- task['Status'],
119
- task['Due Date']
120
- )
121
-
122
- # Display the card
123
- st.markdown(card, unsafe_allow_html=True)
124
-
125
- # Status update dropdown below the card
126
- new_status = st.selectbox(
127
- "Update Status",
128
- ["To Do", "In Progress", "Done"],
129
- index=["To Do", "In Progress", "Done"].index(task['Status']),
130
- key=f"status_{idx}"
131
- )
132
-
133
- if new_status != task['Status']:
134
- st.session_state.tasks.at[idx, 'Status'] = new_status
135
- save_tasks() # Save after updating
136
- st.rerun()
137
-
138
- st.markdown("</div>", unsafe_allow_html=True)
139
- st.write("") # Add some spacing between cards
 
 
 
10
  "Done": "#e6ffe6"
11
  }
12
 
13
+ # Adjust these file paths according to your environment
14
+ TASKS_FILE = "tasks.csv" # Changed from /data/tasks.csv for local testing
15
  ASSIGNEE_FILE = "Assignee.txt"
16
 
17
+ def create_empty_df():
18
+ """Create an empty DataFrame with the required columns"""
19
+ return pd.DataFrame(columns=[
20
+ 'Title', 'Description', 'Assignee', 'Status', 'Due Date'
21
+ ])
22
+
23
  def load_tasks():
24
  """Load tasks from CSV file"""
25
  try:
 
31
  return create_empty_df()
32
 
33
  def save_tasks():
34
+ """Save tasks to CSV file with proper error handling"""
35
  try:
36
  st.session_state.tasks.to_csv(TASKS_FILE, index=False)
37
  except PermissionError:
 
39
  except Exception as e:
40
  st.error(f"Error saving tasks: {str(e)}")
41
 
 
 
 
 
 
 
 
 
 
42
  def load_assignees():
43
  """Load assignees from text file"""
44
  assignees = []
 
51
  if ' ' in name_part:
52
  assignees.append(name_part)
53
  except FileNotFoundError:
54
+ st.error(f"Assignee file '{ASSIGNEE_FILE}' not found!")
55
+ # Return a default list to prevent app from crashing
56
+ return ["User 1", "User 2"]
57
  return assignees
58
 
59
+ # Function to create styled task cards with proper HTML
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  def task_card(title, description, assignee, status, due_date):
61
  color = STATUS_COLORS.get(status, "#ffffff")
62
  card = f"""
 
71
  <p><strong>Assignee:</strong> {assignee}</p>
72
  <p><strong>Due Date:</strong> {due_date}</p>
73
  <p><strong>Description:</strong> {description}</p>
74
+ <div style="margin-top: 15px;"></div>
75
+ </div>
76
  """
77
  return card
78
 
79
+ # Initialize session state ONLY ONCE
80
+ if 'tasks' not in st.session_state:
81
+ st.session_state.tasks = load_tasks()
82
+
83
+ # Load assignees once and reuse
84
+ assignee_list = load_assignees()
85
+
86
+ # App UI starts here
87
  st.title("Company Task Board 🗒️")
88
+
89
+ # Sidebar for new tasks
90
+ with st.sidebar:
91
+ st.header("➕ Add New Task")
92
+ title = st.text_input("Task Title")
93
+ description = st.text_area("Description")
94
+ assignee = st.selectbox("Assignee", assignee_list) # Use the preloaded list
95
+ status = st.selectbox("Status", ["To Do", "In Progress", "Done"])
96
+ due_date = st.date_input("Due Date")
97
+
98
+ if st.button("Add Task"):
99
+ if title: # Basic validation
100
+ new_task = {
101
+ 'Title': title,
102
+ 'Description': description,
103
+ 'Assignee': assignee,
104
+ 'Status': status,
105
+ 'Due Date': due_date
106
+ }
107
+ st.session_state.tasks = pd.concat([
108
+ st.session_state.tasks,
109
+ pd.DataFrame([new_task])
110
+ ], ignore_index=True)
111
+ save_tasks()
112
+ st.success("Task added successfully!")
113
+ else:
114
+ st.warning("Please enter a task title")
115
+
116
  st.divider()
117
 
118
  # Display tasks in cards
119
+ if st.session_state.tasks.empty:
120
+ st.info("No tasks yet. Add your first task using the sidebar.")
121
+ else:
122
+ for idx, task in st.session_state.tasks.iterrows():
123
+ card = task_card(
124
+ task['Title'],
125
+ task['Description'],
126
+ task['Assignee'],
127
+ task['Status'],
128
+ task['Due Date'].strftime('%Y-%m-%d') if isinstance(task['Due Date'], datetime) else task['Due Date']
129
+ )
130
+
131
+ # Display the card
132
+ st.markdown(card, unsafe_allow_html=True)
133
+
134
+ # Status update dropdown below the card
135
+ new_status = st.selectbox(
136
+ "Update Status",
137
+ ["To Do", "In Progress", "Done"],
138
+ index=["To Do", "In Progress", "Done"].index(task['Status']),
139
+ key=f"status_{idx}"
140
+ )
141
+
142
+ if new_status != task['Status']:
143
+ st.session_state.tasks.at[idx, 'Status'] = new_status
144
+ save_tasks() # Save after updating
145
+ st.rerun()
146
+
147
+ st.write("")