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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -10,6 +10,7 @@ import folium
10
  from streamlit_folium import st_folium
11
  import cv2
12
  import numpy as np
 
13
 
14
 
15
  st.set_page_config(page_title="Skin Cancer Dashboard", layout="wide")
@@ -37,14 +38,34 @@ geolocator = Nominatim(user_agent="skin-dashboard", timeout = 10)
37
 
38
  # --- Load Model & Feature Extractor ---
39
  @st.cache_resource
 
40
  def load_image_model(token: str):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  return pipeline(
42
- "image-classification",
43
- MODEL_NAME,
44
- use_auth_token=token,
45
- trust_remote_code=True, # allow custom code in the model repo
46
- device=0,# or -1 for CPU
47
- model_type = "biogpt"
48
  )
49
 
50
  @st.cache_resource
 
10
  from streamlit_folium import st_folium
11
  import cv2
12
  import numpy as np
13
+ from huggingface_hub import snapshot_download
14
 
15
 
16
  st.set_page_config(page_title="Skin Cancer Dashboard", layout="wide")
 
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",
54
+ "num_labels": 2,
55
+ "id2label": { "0": "benign", "1": "malignant" },
56
+ "label2id": { "benign": 0, "malignant": 1 }
57
+ }
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(
65
+ "image-classification",
66
+ model=model,
67
+ feature_extractor=extractor,
68
+ device=0 # or -1 for CPU
 
 
69
  )
70
 
71
  @st.cache_resource