MoritzMMuller commited on
Commit
3567378
·
verified ·
1 Parent(s): 5ee7ab3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -36,18 +36,19 @@ if 'initialized' not in st.session_state:
36
  # Initialize geolocator for free geocoding
37
  geolocator = Nominatim(user_agent="skin-dashboard", timeout = 10)
38
 
39
- # --- Load Model & Feature Extractor ---
40
- @st.cache_resource
41
  @st.cache_resource
42
  def load_image_model(token: str):
43
- # 1) grab *everything* from the remote repo into a local folder
 
 
44
  local_dir = snapshot_download(
45
  repo_id=MODEL_NAME,
46
  use_auth_token=token,
47
- cache_dir="/app/model_cache" # you can pick any path under /app
48
  )
49
 
50
- # 2) write a minimal, valid config.json *into* that folder
51
  cfg = {
52
  "architectures": ["ConvNextForImageClassification"],
53
  "model_type": "convnext",
@@ -58,7 +59,7 @@ def load_image_model(token: str):
58
  with open(os.path.join(local_dir, "config.json"), "w") as f:
59
  json.dump(cfg, f)
60
 
61
- # 3) load extractor & model *from that local snapshot*
62
  extractor = AutoFeatureExtractor.from_pretrained(local_dir)
63
  model = AutoModelForImageClassification.from_pretrained(local_dir)
64
  return pipeline(
 
36
  # Initialize geolocator for free geocoding
37
  geolocator = Nominatim(user_agent="skin-dashboard", timeout = 10)
38
 
39
+
 
40
  @st.cache_resource
41
  def load_image_model(token: str):
42
+ # 1) Download the repo into a writable path
43
+ cache_dir = "/mnt/data/model_cache"
44
+ # snapshot_download will create this folder if it doesn't exist
45
  local_dir = snapshot_download(
46
  repo_id=MODEL_NAME,
47
  use_auth_token=token,
48
+ cache_dir=cache_dir
49
  )
50
 
51
+ # 2) Inject a valid config.json there
52
  cfg = {
53
  "architectures": ["ConvNextForImageClassification"],
54
  "model_type": "convnext",
 
59
  with open(os.path.join(local_dir, "config.json"), "w") as f:
60
  json.dump(cfg, f)
61
 
62
+ # 3) Load from the patched local snapshot
63
  extractor = AutoFeatureExtractor.from_pretrained(local_dir)
64
  model = AutoModelForImageClassification.from_pretrained(local_dir)
65
  return pipeline(