Jitendra12421 commited on
Commit
910e6b7
·
verified ·
1 Parent(s): 495a1f4

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -228,11 +228,30 @@ def attach_market_state(payload: dict) -> dict:
228
  payload["nifty_quote"] = None
229
  payload["nifty_quote_error"] = {"status": 502, "message": str(exc)}
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  t5_latest = payload.get("predictions", {}).get("t5", {}).get("latest") or payload.get("latest") or {}
232
  tomorrow_latest = payload.get("predictions", {}).get("tomorrow", {}).get("latest") or payload.get("tomorrow_latest") or {}
233
  tplus1_latest = payload.get("predictions", {}).get("tplus1", {}).get("latest") or payload.get("tplus1_latest") or {}
234
- mfe_latest = payload.get("predictions", {}).get("mfe", {}).get("latest") or {}
235
- mfe_summary = payload.get("predictions", {}).get("mfe", {}).get("summary") or {}
236
  t5_available = bool(state["t5_available"] and t5_latest.get("prediction"))
237
  tplus1_available = bool(state["tplus1_available"] and tplus1_latest.get("prediction"))
238
  tomorrow_available = bool(tomorrow_latest.get("prediction"))
 
228
  payload["nifty_quote"] = None
229
  payload["nifty_quote_error"] = {"status": 502, "message": str(exc)}
230
 
231
+ import json
232
+ import pandas as pd
233
+ from pathlib import Path
234
+
235
+ # AGGRESSIVE FALLBACK: If runtime.py fails to load it (due to path resolution issues on Hugging Face),
236
+ # we forcefully load it directly from app.py's relative path.
237
+ mfe_summary_fallback = {}
238
+ mfe_latest_fallback = {}
239
+ try:
240
+ models_dir = Path(__file__).resolve().parent / "models"
241
+ mfe_out = models_dir / "nifty_opening_mfe_regressor" / "outputs"
242
+ if (mfe_out / "summary.json").exists():
243
+ mfe_summary_fallback = json.loads((mfe_out / "summary.json").read_text(encoding="utf-8"))
244
+ if (mfe_out / "latest_prediction.csv").exists():
245
+ row = pd.read_csv(mfe_out / "latest_prediction.csv").iloc[-1].to_dict()
246
+ mfe_latest_fallback = {k: (None if pd.isna(v) else v) for k, v in row.items()}
247
+ except Exception as exc:
248
+ print(f"Fallback MFE load failed: {exc}", flush=True)
249
+
250
  t5_latest = payload.get("predictions", {}).get("t5", {}).get("latest") or payload.get("latest") or {}
251
  tomorrow_latest = payload.get("predictions", {}).get("tomorrow", {}).get("latest") or payload.get("tomorrow_latest") or {}
252
  tplus1_latest = payload.get("predictions", {}).get("tplus1", {}).get("latest") or payload.get("tplus1_latest") or {}
253
+ mfe_latest = payload.get("predictions", {}).get("mfe", {}).get("latest") or mfe_latest_fallback
254
+ mfe_summary = payload.get("predictions", {}).get("mfe", {}).get("summary") or mfe_summary_fallback
255
  t5_available = bool(state["t5_available"] and t5_latest.get("prediction"))
256
  tplus1_available = bool(state["tplus1_available"] and tplus1_latest.get("prediction"))
257
  tomorrow_available = bool(tomorrow_latest.get("prediction"))