Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # Dictionary to store notes in memory | |
| notes = {} | |
| def save_note(note_number, content): | |
| if note_number: | |
| notes[int(note_number)] = content | |
| return f"Note {note_number} saved!", {str(k): v for k, v in notes.items()} | |
| return "Please enter a valid note number.", {str(k): v for k, v in notes.items()} | |
| def load_note(note_number): | |
| if note_number and int(note_number) in notes: | |
| return notes[int(note_number)] | |
| return "" | |
| def clear_notes(): | |
| notes.clear() | |
| return "All notes cleared!", {}, "" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## 📝 Simple Gradio Notepad") | |
| with gr.Row(): | |
| note_number = gr.Number(label="Note Number", precision=0) | |
| load_button = gr.Button("Load Note") | |
| clear_button = gr.Button("Clear All Notes") | |
| note_content = gr.Textbox(lines=10, label="Note Content", placeholder="Write your note here...") | |
| save_button = gr.Button("Save Note") | |
| status_output = gr.Textbox(label="Status", interactive=False) | |
| notes_display = gr.JSON(label="Current Notes (in memory)") | |
| # Function bindings | |
| save_button.click(save_note, inputs=[note_number, note_content], outputs=[status_output, notes_display]) | |
| load_button.click(load_note, inputs=note_number, outputs=note_content) | |
| clear_button.click(clear_notes, outputs=[status_output, notes_display, note_content]) | |
| demo.launch() | |