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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -10,26 +10,29 @@ STATUS_COLORS = {
10
  "Done": "#e6ffe6"
11
  }
12
 
13
- # File paths
14
- TASKS_FILE = "tasks.csv"
15
  ASSIGNEE_FILE = "Assignee.txt"
16
 
17
  def load_tasks():
18
  """Load tasks from CSV file"""
19
- if os.path.exists(TASKS_FILE):
20
- try:
21
- # Handle empty files and files with only headers
22
- df = pd.read_csv(TASKS_FILE, parse_dates=['Due Date'])
23
- if df.empty:
24
- return pd.DataFrame(columns=[
25
- 'Title', 'Description', 'Assignee', 'Status', 'Due Date'
26
- ])
27
- return df
28
- except pd.errors.EmptyDataError:
29
- # Return empty dataframe if file is completely empty
30
- return pd.DataFrame(columns=[
31
- 'Title', 'Description', 'Assignee', 'Status', 'Due Date'
32
- ])
 
 
 
 
33
  return pd.DataFrame(columns=[
34
  'Title', 'Description', 'Assignee', 'Status', 'Due Date'
35
  ])
 
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:
19
+ df = pd.read_csv(TASKS_FILE, parse_dates=['Due Date'])
20
+ if df.empty:
21
+ return create_empty_df()
22
+ return df
23
+ except (FileNotFoundError, pd.errors.EmptyDataError):
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:
31
+ st.error("Permission denied! Could not 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
  ])