Spaces:
Runtime error
Runtime error
Download nova_service/context_builder.py from StrategyForge/PRISM-Marketing-Mix-Intelligence: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/spaces/StrategyForge/PRISM-Marketing-Mix-Intelligence/resolve/main/nova_service/context_builder.py
- Command line
-
hf download hf://spaces/StrategyForge/PRISM-Marketing-Mix-Intelligence/nova_service/context_builder.py
-
curl -L -o context_builder.py https://huggingface.co/spaces/StrategyForge/PRISM-Marketing-Mix-Intelligence/resolve/main/nova_service/context_builder.py
1.68 kB
| """Read-only PRISM MMM context contract for an external NOVA LLM agent.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| import pandas as pd | |
| ROOT = Path(__file__).resolve().parents[1] | |
| RESULTS = ROOT / "data" / "model_results" | |
| def build_context(filters: dict | None = None) -> dict: | |
| """Return only model outputs and aggregated facts; never modify PRISM data.""" | |
| filters = filters or {} | |
| metadata = json.loads((RESULTS / "model_metadata.json").read_text(encoding="utf-8")) | |
| coefficients = pd.read_csv(RESULTS / "mmm_coefficients.csv") | |
| predictions = pd.read_csv(RESULTS / "predictions.csv") | |
| contributions = pd.read_csv(RESULTS / "driver_contributions.csv") | |
| if filters.get("date_start"): | |
| predictions = predictions[predictions["date"] >= filters["date_start"]] | |
| contributions = contributions[contributions["date"] >= filters["date_start"]] | |
| if filters.get("date_end"): | |
| predictions = predictions[predictions["date"] <= filters["date_end"]] | |
| contributions = contributions[contributions["date"] <= filters["date_end"]] | |
| driver_summary = contributions.groupby("driver", as_index=False)["contribution_revenue"].sum().sort_values("contribution_revenue", ascending=False) | |
| return {"contract_version": "1.0", "read_only": True, "filters": filters, | |
| "model": metadata, "predictions": predictions.to_dict("records"), | |
| "driver_contributions": driver_summary.to_dict("records"), | |
| "coefficients": coefficients.to_dict("records"), | |
| "guardrail": "Synthetic MMM outputs are demonstration data. State this clearly; do not claim causal production results."} | |