Minahel commited on
Commit
2028181
Β·
verified Β·
1 Parent(s): 546c618

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -0
app.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from datetime import datetime
4
+
5
+ NOTES_FILE = "notes_storage.txt"
6
+
7
+ # Ensure notes file exists
8
+ if not os.path.exists(NOTES_FILE):
9
+ with open(NOTES_FILE, "w", encoding="utf-8") as f:
10
+ pass
11
+
12
+
13
+ # -------- Core Functions -------- #
14
+
15
+ def add_note(title, content):
16
+ if title.strip() == "" or content.strip() == "":
17
+ return "⚠️ Title and content cannot be empty!", get_notes()
18
+
19
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
20
+
21
+ formatted_note = f"""
22
+ πŸ—‚ Title: {title}
23
+ πŸ•’ Time: {timestamp}
24
+ πŸ“ Note:
25
+ {content}
26
+ {'-'*50}
27
+ """
28
+
29
+ with open(NOTES_FILE, "a", encoding="utf-8") as f:
30
+ f.write(formatted_note)
31
+
32
+ return "βœ… Note Added Successfully!", get_notes()
33
+
34
+
35
+ def get_notes():
36
+ with open(NOTES_FILE, "r", encoding="utf-8") as f:
37
+ data = f.read()
38
+
39
+ return data if data else "✨ No notes yet. Start writing something amazing!"
40
+
41
+
42
+ def clear_notes():
43
+ with open(NOTES_FILE, "w", encoding="utf-8") as f:
44
+ f.write("")
45
+ return "πŸ—‘οΈ All notes cleared!", "✨ No notes yet."
46
+
47
+
48
+ def download_notes():
49
+ return NOTES_FILE
50
+
51
+
52
+ # -------- UI Design -------- #
53
+
54
+ with gr.Blocks(
55
+ theme=gr.themes.Soft(
56
+ primary_hue="violet",
57
+ secondary_hue="blue",
58
+ )
59
+ ) as demo:
60
+
61
+ gr.Markdown(
62
+ """
63
+ <h1 style="text-align:center;">πŸ“ Smart Notes Pro</h1>
64
+ <p style="text-align:center; font-size:18px;">
65
+ Beautiful β€’ Organized β€’ Simple β€’ Powerful
66
+ </p>
67
+ """,
68
+ )
69
+
70
+ with gr.Row():
71
+ with gr.Column(scale=1):
72
+ gr.Markdown("### ✍️ Create a New Note")
73
+
74
+ title_input = gr.Textbox(
75
+ label="Title",
76
+ placeholder="Enter note title..."
77
+ )
78
+
79
+ content_input = gr.Textbox(
80
+ label="Content",
81
+ placeholder="Write your note here...",
82
+ lines=8
83
+ )
84
+
85
+ add_btn = gr.Button("βž• Add Note", variant="primary")
86
+ clear_btn = gr.Button("πŸ—‘ Clear All Notes", variant="stop")
87
+
88
+ status_output = gr.Textbox(
89
+ label="Status",
90
+ interactive=False
91
+ )
92
+
93
+ with gr.Column(scale=1):
94
+ gr.Markdown("### πŸ“š Your Notes")
95
+
96
+ notes_display = gr.Textbox(
97
+ lines=20,
98
+ interactive=False
99
+ )
100
+
101
+ refresh_btn = gr.Button("πŸ”„ Refresh Notes")
102
+ download_btn = gr.DownloadButton("πŸ“₯ Download Notes")
103
+
104
+ # Button Interactions
105
+ add_btn.click(
106
+ add_note,
107
+ inputs=[title_input, content_input],
108
+ outputs=[status_output, notes_display]
109
+ )
110
+
111
+ clear_btn.click(
112
+ clear_notes,
113
+ outputs=[status_output, notes_display]
114
+ )
115
+
116
+ refresh_btn.click(
117
+ get_notes,
118
+ outputs=notes_display
119
+ )
120
+
121
+ download_btn.click(
122
+ download_notes,
123
+ outputs=download_btn
124
+ )
125
+
126
+ demo.load(get_notes, outputs=notes_display)
127
+
128
+
129
+ demo.launch(server_name="0.0.0.0")