Adam Cseresznye commited on
Commit
7f75acb
·
1 Parent(s): 1f2e08b

Add copy-to-clipboard button to answer section

Browse files
Files changed (1) hide show
  1. ui/components.py +26 -3
ui/components.py CHANGED
@@ -2,6 +2,7 @@
2
 
3
  from nicegui import ui
4
  from loguru import logger
 
5
 
6
 
7
  def render_loading():
@@ -21,10 +22,28 @@ def render_answer(result):
21
  Args:
22
  result: PipelineResult object with answer, execution_time, finalists, passages
23
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  with ui.column().classes("answer-section w-full"):
25
- # Stats row
26
- with ui.row().classes("items-center gap-3 mb-4"):
27
- with ui.row().classes("gap-2"):
 
28
  ui.label(f"⏱️ {result.execution_time:.1f}s").classes("stats-badge")
29
  ui.label(f"📄 {len(result.finalists)} papers analyzed").classes(
30
  "stats-badge"
@@ -33,6 +52,10 @@ def render_answer(result):
33
  "stats-badge"
34
  )
35
 
 
 
 
 
36
  # Answer text - clean up markdown and display
37
  ui.markdown(result.answer, extras=["tables"]).classes("w-full").style(
38
  "word-wrap: break-word; overflow-wrap: break-word; hyphens: auto; word-break: break-word; line-height: 1.8;"
 
2
 
3
  from nicegui import ui
4
  from loguru import logger
5
+ import json
6
 
7
 
8
  def render_loading():
 
22
  Args:
23
  result: PipelineResult object with answer, execution_time, finalists, passages
24
  """
25
+
26
+ def copy_content():
27
+ """Construct and copy content to clipboard."""
28
+ content = result.answer + "\n\n### Sources Cited\n"
29
+ for idx, passage in enumerate(result.passages):
30
+ metadata = (
31
+ passage.node.metadata if hasattr(passage.node, "metadata") else {}
32
+ )
33
+ title = metadata.get("paper_title", "Unknown Source")
34
+ url = metadata.get("pdf_url", "") or metadata.get("url", "")
35
+ content += f"{idx + 1}. {title} - {url}\n"
36
+
37
+ # Serialize to JSON to handle quotes/newlines safely
38
+ safe_content = json.dumps(content)
39
+ ui.run_javascript(f"navigator.clipboard.writeText({safe_content})")
40
+ ui.notify("Copied to clipboard", type="positive")
41
+
42
  with ui.column().classes("answer-section w-full"):
43
+ # Stats row - responsive layout
44
+ with ui.row().classes("w-full justify-between items-start mb-4 no-wrap"):
45
+ # Stats badges container - allows wrapping internally
46
+ with ui.row().classes("flex-wrap gap-2 items-center"):
47
  ui.label(f"⏱️ {result.execution_time:.1f}s").classes("stats-badge")
48
  ui.label(f"📄 {len(result.finalists)} papers analyzed").classes(
49
  "stats-badge"
 
52
  "stats-badge"
53
  )
54
 
55
+ ui.button(icon="content_copy", on_click=copy_content).props(
56
+ "flat round size=sm"
57
+ ).classes("text-gray-500 shrink-0").tooltip("Copy to clipboard")
58
+
59
  # Answer text - clean up markdown and display
60
  ui.markdown(result.answer, extras=["tables"]).classes("w-full").style(
61
  "word-wrap: break-word; overflow-wrap: break-word; hyphens: auto; word-break: break-word; line-height: 1.8;"