File size: 1,618 Bytes
2224634
e645cfc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline
import datetime

# Initialize components
note_generator = pipeline("text-generation", model="gpt2")
notes_db = []

def save_note(note):
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    notes_db.append({"text": note, "time": timestamp})
    return f"Note saved at {timestamp}"

def get_notes():
    return "\n\n".join([f"{note['time']}:\n{note['text']}" for note in notes_db])

def process_note(input_text, action):
    if action == "Save":
        return save_note(input_text)
    elif action != "Default":
        prompt = f"{action} this text: {input_text}\n\nResult:"
        result = note_generator(prompt, max_length=200)[0]['generated_text']
        return result
    return input_text

with gr.Blocks() as demo:
    gr.Markdown("# Advanced NoteGPT Clone")
    with gr.Tab("Note Editor"):
        with gr.Row():
            with gr.Column():
                user_input = gr.Textbox(label="Your Notes", lines=10)
                action = gr.Radio(["Default", "Summarize", "Expand", "Rephrase", "Save"], 
                                label="Action")
                generate_btn = gr.Button("Process Note")
            with gr.Column():
                output = gr.Textbox(label="Result", lines=10)
    
    with gr.Tab("Saved Notes"):
        notes_display = gr.Textbox(label="Your Saved Notes", lines=20)
        refresh_btn = gr.Button("Refresh Notes")
    
    generate_btn.click(fn=process_note, inputs=[user_input, action], outputs=output)
    refresh_btn.click(fn=get_notes, inputs=None, outputs=notes_display)

demo.launch()