|
import gradio as gr |
|
from transformers import pipeline |
|
import datetime |
|
|
|
|
|
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() |