mc0117 commited on
Commit
87d2f9b
·
1 Parent(s): bab510c

added fallback

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -22,7 +22,7 @@ _dist_cache: dict = {}
22
  def _ensure_data():
23
  if not os.path.exists(DATA_PATH):
24
  from huggingface_hub import hf_hub_download
25
- from huggingface_hub.utils import EntryNotFoundError
26
  os.makedirs(_DATA_DIR, exist_ok=True)
27
  filename = os.path.basename(DATA_PATH)
28
  print(f"Downloading {filename} from HF Hub...")
@@ -35,11 +35,11 @@ def _ensure_data():
35
  local_dir_use_symlinks=False,
36
  token=os.environ.get("HF_TOKEN"),
37
  )
38
- except EntryNotFoundError:
39
- raise RuntimeError(
40
- f"{filename} not found on HF Hub. "
41
- "Call update_season_data() to fetch and upload it first."
42
- )
43
 
44
 
45
  def _get_dist(team: str) -> InningOutcomeDistribution:
 
22
  def _ensure_data():
23
  if not os.path.exists(DATA_PATH):
24
  from huggingface_hub import hf_hub_download
25
+ from huggingface_hub.errors import EntryNotFoundError, RepositoryNotFoundError
26
  os.makedirs(_DATA_DIR, exist_ok=True)
27
  filename = os.path.basename(DATA_PATH)
28
  print(f"Downloading {filename} from HF Hub...")
 
35
  local_dir_use_symlinks=False,
36
  token=os.environ.get("HF_TOKEN"),
37
  )
38
+ except (EntryNotFoundError, RepositoryNotFoundError):
39
+ print(f"{filename} not found on HF Hub. Fetching from Baseball Savant...")
40
+ result = update_season_data()
41
+ if result["status"] != "ok":
42
+ raise RuntimeError(f"Auto-fetch failed: {result['message']}")
43
 
44
 
45
  def _get_dist(team: str) -> InningOutcomeDistribution: