kevinkyi commited on
Commit
712e46c
·
verified ·
1 Parent(s): 121c7d8

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -13,22 +13,21 @@ def _prepare_predictor_dir() -> str:
13
  repo_id=MODEL_REPO_ID,
14
  filename=ZIP_FILENAME,
15
  repo_type="model",
16
- local_dir=os.getenv("HF_HOME", str(pathlib.Path.home() / ".cache" / "huggingface")),
17
- local_dir_use_symlinks=False,
18
  )
19
- # Extract to a writable temp dir
20
  workdir = tempfile.mkdtemp(prefix="ag_predictor_")
21
  with zipfile.ZipFile(local_zip, "r") as zf:
22
  zf.extractall(workdir)
23
- # Some archives place files under a single top-level folder; handle both cases
24
  entries = list(pathlib.Path(workdir).iterdir())
25
  if len(entries) == 1 and entries[0].is_dir():
26
  return str(entries[0])
27
  return workdir
28
 
29
  PREDICTOR_DIR = _prepare_predictor_dir()
30
- # allow cross-version loads; the model is old (<=0.3.1), AG handles migration
31
- PREDICTOR = ag.TabularPredictor.load(PREDICTOR_DIR, require_py_version_match=False)
 
32
 
33
  FEATURE_COLS = ["phone_hours","computer_hours","device_count","sleep_quality","sleep_time","sleep_hours"]
34
  LABEL_MAP = {0: "No (does not use phone before bed)", 1: "Yes (uses phone before bed)"}
@@ -73,6 +72,5 @@ with gr.Blocks() as demo:
73
  for c in comps:
74
  c.change(fn=do_predict, inputs=comps, outputs=out)
75
 
76
- # Spaces looks for a top-level variable named 'demo'
77
  if __name__ == "__main__":
78
  demo.launch()
 
13
  repo_id=MODEL_REPO_ID,
14
  filename=ZIP_FILENAME,
15
  repo_type="model",
16
+ # do NOT pass local_dir_use_symlinks (deprecated)
17
+ # let HF pick the cache dir automatically
18
  )
 
19
  workdir = tempfile.mkdtemp(prefix="ag_predictor_")
20
  with zipfile.ZipFile(local_zip, "r") as zf:
21
  zf.extractall(workdir)
 
22
  entries = list(pathlib.Path(workdir).iterdir())
23
  if len(entries) == 1 and entries[0].is_dir():
24
  return str(entries[0])
25
  return workdir
26
 
27
  PREDICTOR_DIR = _prepare_predictor_dir()
28
+
29
+ # Match the version the predictor was saved with (1.4.0) -> we'll enforce version match
30
+ PREDICTOR = ag.TabularPredictor.load(PREDICTOR_DIR, require_py_version_match=False, require_version_match=True)
31
 
32
  FEATURE_COLS = ["phone_hours","computer_hours","device_count","sleep_quality","sleep_time","sleep_hours"]
33
  LABEL_MAP = {0: "No (does not use phone before bed)", 1: "Yes (uses phone before bed)"}
 
72
  for c in comps:
73
  c.change(fn=do_predict, inputs=comps, outputs=out)
74
 
 
75
  if __name__ == "__main__":
76
  demo.launch()