"""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()