Spaces:
Sleeping
Sleeping
Rajan Sharma
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -178,7 +178,7 @@ def _load_snapshot(path=SNAPSHOT_PATH):
|
|
| 178 |
|
| 179 |
# ---------- Init retrieval engines ----------
|
| 180 |
init_retriever()
|
| 181 |
-
_session_rag = SessionRAG() # in-memory
|
| 182 |
|
| 183 |
# ---------- Executive pre-compute (MDSi block) ----------
|
| 184 |
def _mdsi_block():
|
|
@@ -207,23 +207,37 @@ def clarityops_reply(user_msg, history, tz, uploaded_files_paths):
|
|
| 207 |
ans = "I am ClarityOps, your strategic decision making AI partner."
|
| 208 |
return history + [(user_msg, ans)]
|
| 209 |
|
|
|
|
| 210 |
if uploaded_files_paths:
|
| 211 |
-
|
| 212 |
-
if
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
session_snips = "\n---\n".join(_session_rag.retrieve(
|
| 217 |
"diabetes screening Indigenous Métis mobile program cost throughput outcomes logistics bed flow staffing discharge forecast",
|
| 218 |
k=6
|
| 219 |
))
|
| 220 |
|
|
|
|
| 221 |
snapshot = _load_snapshot()
|
| 222 |
policy_context = retrieve_context(
|
| 223 |
"mobile diabetes screening Indigenous community outreach logistics referral pathways cultural safety data governance cost effectiveness outcomes bed management discharge acceleration ambulance offload"
|
| 224 |
)
|
| 225 |
computed = compute_operational_numbers(snapshot)
|
| 226 |
|
|
|
|
| 227 |
user_lower = (safe_in or "").lower()
|
| 228 |
mdsi_extra = _mdsi_block() if ("diabetes" in user_lower or "mdsi" in user_lower or "mobile screening" in user_lower) else ""
|
| 229 |
|
|
|
|
| 178 |
|
| 179 |
# ---------- Init retrieval engines ----------
|
| 180 |
init_retriever()
|
| 181 |
+
_session_rag = SessionRAG() # in-memory; supports artifacts (CSV columns)
|
| 182 |
|
| 183 |
# ---------- Executive pre-compute (MDSi block) ----------
|
| 184 |
def _mdsi_block():
|
|
|
|
| 207 |
ans = "I am ClarityOps, your strategic decision making AI partner."
|
| 208 |
return history + [(user_msg, ans)]
|
| 209 |
|
| 210 |
+
# ---------- Ingest uploads: now returns chunks + artifacts ----------
|
| 211 |
if uploaded_files_paths:
|
| 212 |
+
ing = extract_text_from_files(uploaded_files_paths)
|
| 213 |
+
chunks = ing.get("chunks", []) if isinstance(ing, dict) else (ing or [])
|
| 214 |
+
artifacts = ing.get("artifacts", []) if isinstance(ing, dict) else []
|
| 215 |
+
if chunks:
|
| 216 |
+
_session_rag.add_docs(chunks)
|
| 217 |
+
if artifacts:
|
| 218 |
+
_session_rag.register_artifacts(artifacts)
|
| 219 |
+
log_event("uploads_added", None, {"chunks": len(chunks), "artifacts": len(artifacts)})
|
| 220 |
+
|
| 221 |
+
# ---------- Deterministic CSV "columns/headers" handler ----------
|
| 222 |
+
if re.search(r"\b(columns?|headers?)\b", (safe_in or "").lower()):
|
| 223 |
+
cols = _session_rag.get_latest_csv_columns()
|
| 224 |
+
if cols:
|
| 225 |
+
return history + [(user_msg, "Here are the column names from your most recent CSV upload:\n\n- " + "\n- ".join(cols))]
|
| 226 |
+
|
| 227 |
+
# Retrieve from session uploads (text chunks)
|
| 228 |
session_snips = "\n---\n".join(_session_rag.retrieve(
|
| 229 |
"diabetes screening Indigenous Métis mobile program cost throughput outcomes logistics bed flow staffing discharge forecast",
|
| 230 |
k=6
|
| 231 |
))
|
| 232 |
|
| 233 |
+
# Load daily snapshot + policies + computed ops numbers
|
| 234 |
snapshot = _load_snapshot()
|
| 235 |
policy_context = retrieve_context(
|
| 236 |
"mobile diabetes screening Indigenous community outreach logistics referral pathways cultural safety data governance cost effectiveness outcomes bed management discharge acceleration ambulance offload"
|
| 237 |
)
|
| 238 |
computed = compute_operational_numbers(snapshot)
|
| 239 |
|
| 240 |
+
# Exec scenario detect (MDSi)
|
| 241 |
user_lower = (safe_in or "").lower()
|
| 242 |
mdsi_extra = _mdsi_block() if ("diabetes" in user_lower or "mdsi" in user_lower or "mobile screening" in user_lower) else ""
|
| 243 |
|