Spaces:
Runtime error
Runtime error
update app.py
Browse files
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 |
-
|
| 72 |
-
if not
|
| 73 |
-
md = "## No
|
| 74 |
-
return existing_files, md, "No report generated (no
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 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 |
-
|
| 89 |
-
|
| 90 |
-
|
| 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
|