Rausda6 commited on
Commit
16ead7c
·
verified ·
1 Parent(s): b776b81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -5
app.py CHANGED
@@ -10,15 +10,21 @@ from PIL import Image, ImageDraw
10
  import torch
11
  import torch.nn.functional as F
12
  import torchvision.transforms.functional as TF
13
- from transformers import AutoModel # trust_remote_code=True
 
 
 
14
 
15
- import gradio as gr
16
 
17
  # ============================
18
  # Config
19
  # ============================
20
- DEFAULT_MODEL_ID = "facebook/dinov3-vits16plus-pretrain-lvd1689m"
21
- ALT_MODEL_ID = "facebook/dinov3-vith16plus-pretrain-lvd1689m"
 
 
 
 
22
  AVAILABLE_MODELS = [DEFAULT_MODEL_ID, ALT_MODEL_ID]
23
 
24
  PATCH_SIZE = 16
@@ -45,7 +51,7 @@ _model_cache = {}
45
  _current_model_id = None
46
  model = None
47
 
48
- def load_model_from_hub(model_id: str):
49
  print(f"Loading model '{model_id}' from HF Hub…")
50
  token = os.environ.get("HF_TOKEN")
51
  mdl = AutoModel.from_pretrained(model_id, token=token, trust_remote_code=True)
@@ -53,6 +59,24 @@ def load_model_from_hub(model_id: str):
53
  print(f"✅ Loaded '{model_id}' on {DEVICE}")
54
  return mdl
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  def get_model(model_id: str):
57
  if model_id in _model_cache:
58
  return _model_cache[model_id]
 
10
  import torch
11
  import torch.nn.functional as F
12
  import torchvision.transforms.functional as TF
13
+ #from transformers import AutoModel # trust_remote_code=True
14
+ from transformers import pipeline
15
+
16
+
17
 
 
18
 
19
  # ============================
20
  # Config
21
  # ============================
22
+ #DEFAULT_MODEL_ID = "facebook/dinov3-vits16plus-pretrain-lvd1689m"
23
+ #ALT_MODEL_ID = "facebook/dinov3-vith16plus-pretrain-lvd1689m"
24
+
25
+ DEFAULT_MODEL_ID = "onnx-community/dinov3-vits16-pretrain-lvd1689m-ONNX"
26
+ ALT_MODEL_ID = "onnx-community/dinov3-vith16-pretrain-lvd1689m-ONNX"
27
+
28
  AVAILABLE_MODELS = [DEFAULT_MODEL_ID, ALT_MODEL_ID]
29
 
30
  PATCH_SIZE = 16
 
51
  _current_model_id = None
52
  model = None
53
 
54
+ def load_model_from_hubold(model_id: str):
55
  print(f"Loading model '{model_id}' from HF Hub…")
56
  token = os.environ.get("HF_TOKEN")
57
  mdl = AutoModel.from_pretrained(model_id, token=token, trust_remote_code=True)
 
59
  print(f"✅ Loaded '{model_id}' on {DEVICE}")
60
  return mdl
61
 
62
+
63
+ def load_model_from_hub(model_id: str):
64
+ print(f"Loading model '{model_id}' from HF Hub…")
65
+ token = os.environ.get("HF_TOKEN")
66
+ # Use pipeline instead of AutoModel
67
+ extractor = pipeline(
68
+ "image-feature-extraction",
69
+ model=model_id,
70
+ token=token,
71
+ trust_remote_code=True,
72
+ device=0 if DEVICE == "cuda" else -1,
73
+ )
74
+ print(f"✅ Loaded '{model_id}' on {DEVICE}")
75
+ return extractor
76
+
77
+
78
+
79
+
80
  def get_model(model_id: str):
81
  if model_id in _model_cache:
82
  return _model_cache[model_id]