Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 40 |
-
@st.cache_resource
|
| 41 |
@st.cache_resource
|
| 42 |
def load_image_model(token: str):
|
| 43 |
-
# 1)
|
|
|
|
|
|
|
| 44 |
local_dir = snapshot_download(
|
| 45 |
repo_id=MODEL_NAME,
|
| 46 |
use_auth_token=token,
|
| 47 |
-
cache_dir=
|
| 48 |
)
|
| 49 |
|
| 50 |
-
# 2)
|
| 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)
|
| 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(
|