cnxoo commited on
Commit
c286fcf
·
verified ·
1 Parent(s): 4a3371f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +29 -3
main.py CHANGED
@@ -110,6 +110,32 @@ else:
110
  best_th = np.full(C, 0.5, dtype="float32")
111
 
112
  # ---------------------- Load derm-foundation ----------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  logger.info("Loading Derm Foundation (first time may take a while)...")
114
  try:
115
  if DERM_LOCAL_DIR and os.path.isdir(DERM_LOCAL_DIR) and os.path.exists(os.path.join(DERM_LOCAL_DIR, "saved_model.pb")):
@@ -121,16 +147,16 @@ try:
121
  repo_id=DERM_MODEL_ID,
122
  repo_type="model",
123
  allow_patterns=["saved_model.pb", "variables/*"],
 
124
  )
125
  logger.info(f"Derm Foundation downloaded to: {derm_dir}")
126
 
127
  derm = tf.saved_model.load(derm_dir)
128
- infer = derm.signatures["serving_default"] # call with key 'inputs'
129
  except Exception as e:
130
  raise RuntimeError(
131
  f"Failed to load derm-foundation: {e}. "
132
- "Make sure you accepted the model terms on Hugging Face, "
133
- "or set DERM_LOCAL_DIR to a local SavedModel path."
134
  )
135
 
136
  # ---------------------- Utils ----------------------
 
110
  best_th = np.full(C, 0.5, dtype="float32")
111
 
112
  # ---------------------- Load derm-foundation ----------------------
113
+ # logger.info("Loading Derm Foundation (first time may take a while)...")
114
+ # try:
115
+ # if DERM_LOCAL_DIR and os.path.isdir(DERM_LOCAL_DIR) and os.path.exists(os.path.join(DERM_LOCAL_DIR, "saved_model.pb")):
116
+ # derm_dir = DERM_LOCAL_DIR
117
+ # logger.info(f"Loaded Derm Foundation from local: {DERM_LOCAL_DIR}")
118
+ # else:
119
+ # logger.info(f"Downloading derm-foundation from hub: {DERM_MODEL_ID}")
120
+ # derm_dir = snapshot_download(
121
+ # repo_id=DERM_MODEL_ID,
122
+ # repo_type="model",
123
+ # allow_patterns=["saved_model.pb", "variables/*"],
124
+ # )
125
+ # logger.info(f"Derm Foundation downloaded to: {derm_dir}")
126
+
127
+ # derm = tf.saved_model.load(derm_dir)
128
+ # infer = derm.signatures["serving_default"] # call with key 'inputs'
129
+ # except Exception as e:
130
+ # raise RuntimeError(
131
+ # f"Failed to load derm-foundation: {e}. "
132
+ # "Make sure you accepted the model terms on Hugging Face, "
133
+ # "or set DERM_LOCAL_DIR to a local SavedModel path."
134
+ # )
135
+ from huggingface_hub import snapshot_download
136
+
137
+ HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_HUB_TOKEN")
138
+
139
  logger.info("Loading Derm Foundation (first time may take a while)...")
140
  try:
141
  if DERM_LOCAL_DIR and os.path.isdir(DERM_LOCAL_DIR) and os.path.exists(os.path.join(DERM_LOCAL_DIR, "saved_model.pb")):
 
147
  repo_id=DERM_MODEL_ID,
148
  repo_type="model",
149
  allow_patterns=["saved_model.pb", "variables/*"],
150
+ token=HF_TOKEN, # ← เพิ่มบรรทัดนี้
151
  )
152
  logger.info(f"Derm Foundation downloaded to: {derm_dir}")
153
 
154
  derm = tf.saved_model.load(derm_dir)
155
+ infer = derm.signatures["serving_default"]
156
  except Exception as e:
157
  raise RuntimeError(
158
  f"Failed to load derm-foundation: {e}. "
159
+ "Make sure you accepted the model terms and set HF_TOKEN in Space Settings."
 
160
  )
161
 
162
  # ---------------------- Utils ----------------------