File size: 2,760 Bytes
7e99a66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b9f354d
7e99a66
b9f354d
7e99a66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Interactive Lynote Notes demo (kept ready for PRO hosting).

Paste text, get a cited note, then ask questions grounded in the same text.
The demo uses the library's offline extractive provider, so it needs no model
and no API key — only Gradio and the lynote-notes package.
"""

import tempfile

import gradio as gr

from lynote_notes import Workspace

MAX_CHARS = 5_000
UTM = (
    "https://lynote.ai/ai-notes?utm_source=huggingface"
    "&utm_medium=space&utm_campaign=hf_launch&utm_content=oss_notes"
)


def _workspace(text: str) -> Workspace:
    ws = Workspace(tempfile.mkdtemp())
    ws.add_text(text, "Pasted text")
    return ws


def make_note(text: str, title: str):
    text = (text or "").strip()
    if len(text) < 80:
        return "Add at least 80 characters of source text."
    if len(text) > MAX_CHARS:
        return f"Input is limited to {MAX_CHARS:,} characters in this demo."
    ws = _workspace(text)
    note = ws.make_note(title or "Your note")
    return ws.export_note(note, "md")


def ask_question(text: str, question: str):
    text = (text or "").strip()
    question = (question or "").strip()
    if not text or not question:
        return "Paste some source text and ask a question."
    ws = _workspace(text)
    answer = ws.ask(question)
    lines = [answer.text, ""]
    for index, citation in enumerate(answer.citations, start=1):
        lines.append(f"[{index}] {citation.source_title} · {citation.locator} — {citation.snippet}")
    lines.append("")
    lines.append(f"Try the full product: {UTM}")
    return "\n".join(lines)


with gr.Blocks(title="AI Notes — Source-Grounded AI Note Taker") as demo:
    gr.Markdown(
        "# 📝 AI Notes\n"
        "Source-grounded notes with citations — every bullet links back to the exact "
        "source chunk. Open source: [github.com/lynote-ai/lynote-notes]"
        "(https://github.com/lynote-ai/lynote-notes)"
    )
    source = gr.Textbox(
        label="Source text (80–5,000 characters)",
        placeholder="Paste a lecture transcript, article, or meeting notes…",
        lines=10,
    )
    with gr.Tab("Generate note"):
        title = gr.Textbox(label="Note title", value="Your note")
        note_button = gr.Button("Generate cited note", variant="primary")
        note_output = gr.Markdown()
        note_button.click(make_note, inputs=[source, title], outputs=note_output)
    with gr.Tab("Ask a question"):
        question = gr.Textbox(label="Question", placeholder="What did we decide about pricing?")
        ask_button = gr.Button("Ask", variant="primary")
        answer_output = gr.Markdown()
        ask_button.click(ask_question, inputs=[source, question], outputs=answer_output)

if __name__ == "__main__":
    demo.launch()