File size: 3,108 Bytes
2028181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63e3b8c
2028181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63e3b8c
 
 
2028181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63e3b8c
2028181
 
 
63e3b8c
2028181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63e3b8c
2028181
 
 
 
 
 
 
 
 
 
63e3b8c
2028181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63e3b8c
 
 
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import gradio as gr
import os
from datetime import datetime

NOTES_FILE = "notes_storage.txt"

# Ensure notes file exists
if not os.path.exists(NOTES_FILE):
    with open(NOTES_FILE, "w", encoding="utf-8") as f:
        pass


# -------- Core Functions -------- #

def add_note(title, content):
    if not title.strip() or not content.strip():
        return "⚠️ Title and content cannot be empty!", get_notes()

    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    formatted_note = f"""
πŸ—‚ Title: {title}
πŸ•’ Time: {timestamp}
πŸ“ Note:
{content}
{'-'*50}
"""

    with open(NOTES_FILE, "a", encoding="utf-8") as f:
        f.write(formatted_note)

    return "βœ… Note Added Successfully!", get_notes()


def get_notes():
    if not os.path.exists(NOTES_FILE):
        return "✨ No notes yet."

    with open(NOTES_FILE, "r", encoding="utf-8") as f:
        data = f.read()

    return data if data else "✨ No notes yet. Start writing something amazing!"


def clear_notes():
    with open(NOTES_FILE, "w", encoding="utf-8") as f:
        f.write("")
    return "πŸ—‘οΈ All notes cleared!", "✨ No notes yet."


def download_notes():
    return NOTES_FILE


# -------- UI Design -------- #

with gr.Blocks(
    theme=gr.themes.Soft(
        primary_hue="violet",
        secondary_hue="blue",
    )
) as demo:

    gr.Markdown(
        """
        <h1 style="text-align:center;">πŸ“ Smart Notes Pro</h1>
        <p style="text-align:center; font-size:18px;">
        Beautiful β€’ Organized β€’ Simple β€’ Powerful
        </p>
        """
    )

    with gr.Row():
        with gr.Column():
            gr.Markdown("### ✍️ Create a New Note")

            title_input = gr.Textbox(
                label="Title",
                placeholder="Enter note title..."
            )

            content_input = gr.Textbox(
                label="Content",
                placeholder="Write your note here...",
                lines=8
            )

            add_btn = gr.Button("βž• Add Note", variant="primary")
            clear_btn = gr.Button("πŸ—‘ Clear All Notes", variant="stop")

            status_output = gr.Textbox(
                label="Status",
                interactive=False
            )

        with gr.Column():
            gr.Markdown("### πŸ“š Your Notes")

            notes_display = gr.Textbox(
                lines=20,
                interactive=False
            )

            refresh_btn = gr.Button("πŸ”„ Refresh Notes")
            download_btn = gr.DownloadButton("πŸ“₯ Download Notes")

    # Button Actions
    add_btn.click(
        add_note,
        inputs=[title_input, content_input],
        outputs=[status_output, notes_display]
    )

    clear_btn.click(
        clear_notes,
        outputs=[status_output, notes_display]
    )

    refresh_btn.click(
        get_notes,
        outputs=notes_display
    )

    download_btn.click(
        download_notes,
        outputs=download_btn
    )

    demo.load(get_notes, outputs=notes_display)


# πŸ”₯ IMPORTANT FIX FOR HUGGING FACE
if __name__ == "__main__":
    demo.launch()