ghaffarmumtat123 commited on
Commit
ba0b98e
·
verified ·
1 Parent(s): 2a853a1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import csv
3
+
4
+ # Initialize an empty list for storing the daily routine
5
+ daily_routine = []
6
+
7
+ # Function to add task for each hour from 6 AM to 6 PM
8
+ def add_task_for_hour(hour):
9
+ # Format hour (6:00 AM, 7:00 AM, ..., 6:00 PM)
10
+ time_str = f"{hour}:00"
11
+
12
+ # Streamlit user input for each task
13
+ task = st.text_input(f"Enter the task for {time_str}:")
14
+ description = st.text_area(f"Enter the description for {task}:", height=100)
15
+
16
+ if task and description:
17
+ # Add the task to the list
18
+ daily_routine.append({"time": time_str, "task": task, "description": description})
19
+ st.success(f"Task for {time_str} added successfully!")
20
+
21
+ # Function to display the to-do list
22
+ def display_todo_list():
23
+ if len(daily_routine) == 0:
24
+ st.write("No tasks added yet.")
25
+ return
26
+
27
+ st.subheader("==== Daily Routine To-Do List (6 AM to 6 PM) ====")
28
+ for task in daily_routine:
29
+ st.write(f"**Time**: {task['time']}")
30
+ st.write(f"**Task**: {task['task']}")
31
+ st.write(f"**Description**: {task['description']}")
32
+ st.markdown("---")
33
+
34
+ # Function to save the daily routine to a CSV file
35
+ def save_to_csv(filename):
36
+ try:
37
+ with open(filename, mode="w", newline="") as file:
38
+ writer = csv.writer(file)
39
+ writer.writerow(["Time", "Task", "Description"]) # Write headers
40
+ for task in daily_routine:
41
+ writer.writerow([task['time'], task['task'], task['description']])
42
+
43
+ st.success(f"To-do list saved as '{filename}'")
44
+ except Exception as e:
45
+ st.error(f"Error: {e}")
46
+
47
+ # Streamlit UI
48
+ def main():
49
+ st.title("Daily Routine To-Do List (6 AM - 6 PM)")
50
+
51
+ # Loop through the hours from 6 AM to 6 PM
52
+ for hour in range(6, 19): # Loop from 6 AM (6) to 6 PM (18)
53
+ add_task_for_hour(hour)
54
+
55
+ # Display the to-do list
56
+ if len(daily_routine) > 0:
57
+ if st.button("Display To-Do List"):
58
+ display_todo_list()
59
+
60
+ # Save the list to a CSV file
61
+ if st.button("Save to CSV"):
62
+ save_to_csv('/app/daily_routine.csv') # Path within Hugging Face Spaces
63
+
64
+ if __name__ == "__main__":
65
+ main()