kabdull1 commited on
Commit
bac4599
·
verified ·
1 Parent(s): e63ef31

update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -24
app.py CHANGED
@@ -66,38 +66,28 @@ def _save_notebook_markdown(*, notebook_id: str, subdir: str, prefix: str, conte
66
 
67
  def generate_report(notebook_id: str, existing_files):
68
  """
69
- Generate a report from the ingested sources.
70
  """
71
- events = list_source_events(notebook_id)
72
- if not events:
73
- md = "## No sources ingested\nUpload a PDF (or add a source) first."
74
- return existing_files, md, "No report generated (no sources)."
75
-
76
- src_lines = "\n".join(
77
- [
78
- f"- `{e.get('original_filename')}`"
79
- if e.get("kind") == "file"
80
- else f"- `{e.get('url')}`"
81
- for e in events
82
- ]
83
  )
84
- now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
85
-
86
- report_md = f"""# Report
87
 
88
- Generated from your ingested sources.
89
-
90
- **Notebook:** `{selected_notebook}`
91
- **Generated:** `{now}`
92
-
93
- ### Ingested sources
94
- {src_lines}
95
- """
96
 
97
  files = list(existing_files) if existing_files else []
98
  report_path = _save_notebook_markdown(
99
  notebook_id=notebook_id, subdir="reports", prefix="report", content=report_md
100
  )
 
101
  report_name = report_path.name
102
  if report_name not in files:
103
  files = [report_name] + files
 
66
 
67
  def generate_report(notebook_id: str, existing_files):
68
  """
69
+ Generate a report from the ingested sources using RAG, save it, and return preview + file list.
70
  """
71
+ notebook_id = (notebook_id or "").strip()
72
+ if not notebook_id:
73
+ md = "## No notebook selected\nPlease select a notebook first."
74
+ return existing_files, md, "No report generated (no notebook selected)."
75
+
76
+ report_md = rag_generate_report(
77
+ persist_directory=_chroma_dir(notebook_id),
78
+ title="Report",
79
+ focus_prompt="",
 
 
 
80
  )
 
 
 
81
 
82
+ # Don't save error reports
83
+ if report_md.startswith("No sources") or report_md.startswith("Unable to retrieve"):
84
+ return existing_files, report_md, "Report could not be generated. Upload/ingest sources first."
 
 
 
 
 
85
 
86
  files = list(existing_files) if existing_files else []
87
  report_path = _save_notebook_markdown(
88
  notebook_id=notebook_id, subdir="reports", prefix="report", content=report_md
89
  )
90
+
91
  report_name = report_path.name
92
  if report_name not in files:
93
  files = [report_name] + files