Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,32 +43,31 @@ geolocator = Nominatim(user_agent="skin-dashboard", timeout = 10)
|
|
43 |
|
44 |
@st.cache_resource
|
45 |
def load_image_model(token: str):
|
46 |
-
# 1)
|
47 |
extractor = AutoFeatureExtractor.from_pretrained(
|
48 |
-
|
49 |
-
use_auth_token=token
|
50 |
)
|
51 |
|
52 |
-
# 2)
|
53 |
config = ConvNextConfig(
|
54 |
num_labels=2,
|
55 |
id2label={0: "benign", 1: "malignant"},
|
56 |
-
label2id={"benign": 0, "malignant": 1}
|
57 |
)
|
58 |
|
59 |
-
# 3)
|
60 |
model = AutoModelForImageClassification.from_pretrained(
|
61 |
MODEL_NAME,
|
62 |
config=config,
|
63 |
-
use_auth_token=token
|
64 |
)
|
65 |
|
66 |
-
# 4)
|
67 |
return pipeline(
|
68 |
"image-classification",
|
69 |
model=model,
|
70 |
feature_extractor=extractor,
|
71 |
-
device=0 # or -1 for CPU
|
72 |
)
|
73 |
|
74 |
@st.cache_resource
|
|
|
43 |
|
44 |
@st.cache_resource
|
45 |
def load_image_model(token: str):
|
46 |
+
# 1) Grab a working ConvNeXt feature extractor from the official base model
|
47 |
extractor = AutoFeatureExtractor.from_pretrained(
|
48 |
+
"microsoft/convnext-base-224"
|
|
|
49 |
)
|
50 |
|
51 |
+
# 2) Build a minimal ConvNextConfig that matches your fine-tuned head
|
52 |
config = ConvNextConfig(
|
53 |
num_labels=2,
|
54 |
id2label={0: "benign", 1: "malignant"},
|
55 |
+
label2id={"benign": 0, "malignant": 1},
|
56 |
)
|
57 |
|
58 |
+
# 3) Load *just the weights* from your repo, using the config override
|
59 |
model = AutoModelForImageClassification.from_pretrained(
|
60 |
MODEL_NAME,
|
61 |
config=config,
|
62 |
+
use_auth_token=token,
|
63 |
)
|
64 |
|
65 |
+
# 4) Return the pipeline
|
66 |
return pipeline(
|
67 |
"image-classification",
|
68 |
model=model,
|
69 |
feature_extractor=extractor,
|
70 |
+
device=0, # or -1 for CPU
|
71 |
)
|
72 |
|
73 |
@st.cache_resource
|