Upload app.py
Browse files227 unmodified lines228229230231232233234235236237238227 unmodified linespayload["nifty_quote"] = Nonepayload["nifty_quote_error"] = {"status": 502, "message": str(exc)}t5_latest = payload.get("predictions", {}).get("t5", {}).get("latest") or payload.get("latest") or {}tomorrow_latest = payload.get("predictions", {}).get("tomorrow", {}).get("latest") or payload.get("tomorrow_latest") or {}tplus1_latest = payload.get("predictions", {}).get("tplus1", {}).get("latest") or payload.get("tplus1_latest") or {}mfe_latest = payload.get("predictions", {}).get("mfe", {}).get("latest") or {}mfe_summary = payload.get("predictions", {}).get("mfe", {}).get("summary") or {}t5_available = bool(state["t5_available"] and t5_latest.get("prediction"))tplus1_available = bool(state["tplus1_available"] and tplus1_latest.get("prediction"))tomorrow_available = bool(tomorrow_latest.get("prediction"))227 unmodified lines228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257227 unmodified linespayload["nifty_quote"] = Nonepayload["nifty_quote_error"] = {"status": 502, "message": str(exc)}import jsonimport pandas as pdfrom pathlib import Path# AGGRESSIVE FALLBACK: If runtime.py fails to load it (due to path resolution issues on Hugging Face),# we forcefully load it directly from app.py's relative path.mfe_summary_fallback = {}mfe_latest_fallback = {}try:models_dir = Path(__file__).resolve().parent / "models"mfe_out = models_dir / "nifty_opening_mfe_regressor" / "outputs"if (mfe_out / "summary.json").exists():mfe_summary_fallback = json.loads((mfe_out / "summary.json").read_text(encoding="utf-8"))if (mfe_out / "latest_prediction.csv").exists():row = pd.read_csv(mfe_out / "latest_prediction.csv").iloc[-1].to_dict()mfe_latest_fallback = {k: (None if pd.isna(v) else v) for k, v in row.items()}except Exception as exc:print(f"Fallback MFE load failed: {exc}", flush=True)t5_latest = payload.get("predictions", {}).get("t5", {}).get("latest") or payload.get("latest") or {}tomorrow_latest = payload.get("predictions", {}).get("tomorrow", {}).get("latest") or payload.get("tomorrow_latest") or {}tplus1_latest = payload.get("predictions", {}).get("tplus1", {}).get("latest") or payload.get("tplus1_latest") or {}mfe_latest = payload.get("predictions", {}).get("mfe", {}).get("latest") or mfe_latest_fallbackmfe_summary = payload.get("predictions", {}).get("mfe", {}).get("summary") or mfe_summary_fallbackt5_available = bool(state["t5_available"] and t5_latest.get("prediction"))tplus1_available = bool(state["tplus1_available"] and tplus1_latest.get("prediction"))tomorrow_available = bool(tomorrow_latest.get("prediction"))
app.py+21-2