-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.py
73 lines (64 loc) · 2.18 KB
/
home.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import streamlit as st
st.set_page_config(
page_title="Multipage app",
page_icon="😆"
)
st.sidebar.success("select the pages")
import os
import streamlit as st
# Function to add a new note
def add_note():
note = st.text_input("Enter your note:")
if st.button("Add Note", key="add_note_button"):
if note:
note_number = len(os.listdir("notes")) + 1
note_filename = f"note_{note_number}.txt"
with open(os.path.join("notes", note_filename), "w") as file:
file.write(note)
st.success("Note added successfully!")
else:
st.error("Please enter a note.")
# Function to view all notes
def view_notes():
note_files = os.listdir("notes")
if note_files:
st.subheader("Your Notes:")
for note_filename in note_files:
with open(os.path.join("notes", note_filename), "r") as file:
note_content = file.read()
st.write(f"- {note_content}")
else:
st.subheader("Your Notes:")
st.write("No notes found.")
# Function to delete a note
def delete_note():
note_files = os.listdir("notes")
if note_files:
options = [note_filename for note_filename in note_files]
selected_option = st.selectbox("Select a note to delete:", options)
if st.button("Delete Note", key="delete_note_button"):
os.remove(os.path.join("notes", selected_option))
st.success("Note deleted successfully!")
else:
st.error("No notes found to delete.")
# Main function to run the Streamlit app
def main():
st.title("Notes App")
# Create notes directory if it doesn't exist
if not os.path.exists("notes"):
os.makedirs("notes")
st.sidebar.header("Menu")
menu_options = ["Add Note", "View Notes", "Delete Note"]
choice = st.sidebar.selectbox("Select an option:", menu_options)
if choice == "Add Note":
st.header("Add Note")
add_note()
elif choice == "View Notes":
st.header("View Notes")
view_notes()
elif choice == "Delete Note":
st.header("Delete Note")
delete_note()
# Run the Streamlit app
if __name__ == "__main__":
main()