P2SAMAPA commited on
Commit
85c62a3
·
unverified ·
1 Parent(s): 980e9cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -31,17 +31,18 @@ HF_SPACE_RAW = "https://huggingface.co/spaces/P2SAMAPA/P2-ETF-TFT-PREDICTOR/reso
31
 
32
  @st.cache_data(ttl=1800) # refresh cache every 30 min
33
  def load_model_outputs():
34
- """Load pre-computed model outputs from HF Space repo."""
35
  try:
36
  url = f"{HF_SPACE_RAW}/model_outputs.npz?t={int(time.time())}"
37
  r = requests.get(url, timeout=60)
38
  if r.status_code != 200:
39
- return None, f"model_outputs.npz not found (HTTP {r.status_code})"
40
  from io import BytesIO
41
- data = np.load(BytesIO(r.content), allow_pickle=True)
 
 
42
  return data, None
43
  except Exception as e:
44
- return None, str(e)
45
 
46
 
47
  @st.cache_data(ttl=1800)
 
31
 
32
  @st.cache_data(ttl=1800) # refresh cache every 30 min
33
  def load_model_outputs():
 
34
  try:
35
  url = f"{HF_SPACE_RAW}/model_outputs.npz?t={int(time.time())}"
36
  r = requests.get(url, timeout=60)
37
  if r.status_code != 200:
38
+ return {}, f"model_outputs.npz not found (HTTP {r.status_code})"
39
  from io import BytesIO
40
+ npz = np.load(BytesIO(r.content), allow_pickle=True)
41
+ # Convert NpzFile → plain dict so st.cache_data can pickle it
42
+ data = {k: npz[k] for k in npz.files}
43
  return data, None
44
  except Exception as e:
45
+ return {}, str(e)
46
 
47
 
48
  @st.cache_data(ttl=1800)