Spaces:
Sleeping
Sleeping
lastdefiance20
commited on
Commit
·
54ae859
1
Parent(s):
7769318
Fix huggingface model loading problem
Browse files- .gitignore +1 -0
- canvas.py +10 -5
- requirements.txt +2 -1
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
/__pycache__
|
canvas.py
CHANGED
@@ -13,7 +13,7 @@ from pathlib import Path
|
|
13 |
import numpy as np
|
14 |
from matplotlib import pyplot as plt
|
15 |
from sklearn.cluster import KMeans
|
16 |
-
|
17 |
class BaseModelYamlJsonMixin:
|
18 |
"""
|
19 |
BaseModel with helper methods for loading and saving to yaml/json format.
|
@@ -86,7 +86,8 @@ class KMeansActionTokenizer():
|
|
86 |
def from_pretrained(cls, model_path: str | Path):
|
87 |
model_path = Path(model_path)
|
88 |
self = cls()
|
89 |
-
|
|
|
90 |
self.kmeans = pickle.load(file)
|
91 |
self.action_count = self.kmeans.n_clusters
|
92 |
# assert self.action_count == 32
|
@@ -201,12 +202,16 @@ class Idefics2Pipeline():
|
|
201 |
|
202 |
@classmethod
|
203 |
def from_pretrained(cls, pretrained_model_name_or_path: str):
|
204 |
-
if not isinstance(pretrained_model_name_or_path, Path):
|
205 |
-
pretrained_model_name_or_path = Path(pretrained_model_name_or_path)
|
206 |
|
|
|
|
|
207 |
config = Idefics2PipelineConfig.model_validate_json(
|
208 |
-
(
|
209 |
)
|
|
|
|
|
|
|
|
|
210 |
model = Idefics2ForConditionalGeneration.from_pretrained(pretrained_model_name_or_path)
|
211 |
processor = Idefics2Processor.from_pretrained(pretrained_model_name_or_path)
|
212 |
model.eval()
|
|
|
13 |
import numpy as np
|
14 |
from matplotlib import pyplot as plt
|
15 |
from sklearn.cluster import KMeans
|
16 |
+
from huggingface_hub import hf_hub_download
|
17 |
class BaseModelYamlJsonMixin:
|
18 |
"""
|
19 |
BaseModel with helper methods for loading and saving to yaml/json format.
|
|
|
86 |
def from_pretrained(cls, model_path: str | Path):
|
87 |
model_path = Path(model_path)
|
88 |
self = cls()
|
89 |
+
action_tokenizer_path = hf_hub_download(repo_id=str(model_path), filename="tokenizer.pkl")
|
90 |
+
with open(action_tokenizer_path, "rb") as file:
|
91 |
self.kmeans = pickle.load(file)
|
92 |
self.action_count = self.kmeans.n_clusters
|
93 |
# assert self.action_count == 32
|
|
|
202 |
|
203 |
@classmethod
|
204 |
def from_pretrained(cls, pretrained_model_name_or_path: str):
|
|
|
|
|
205 |
|
206 |
+
pipeline_config_path = hf_hub_download(repo_id=pretrained_model_name_or_path, filename="pipeline_config.json")
|
207 |
+
pipeline_config_path = Path(pipeline_config_path)
|
208 |
config = Idefics2PipelineConfig.model_validate_json(
|
209 |
+
(pipeline_config_path).read_text()
|
210 |
)
|
211 |
+
|
212 |
+
if not isinstance(pretrained_model_name_or_path, Path):
|
213 |
+
pretrained_model_name_or_path = Path(pretrained_model_name_or_path)
|
214 |
+
|
215 |
model = Idefics2ForConditionalGeneration.from_pretrained(pretrained_model_name_or_path)
|
216 |
processor = Idefics2Processor.from_pretrained(pretrained_model_name_or_path)
|
217 |
model.eval()
|
requirements.txt
CHANGED
@@ -5,4 +5,5 @@ numpy==2.1.3
|
|
5 |
torch==2.4.0
|
6 |
pydantic==2.9.2
|
7 |
scikit-learn==1.5.2
|
8 |
-
matplotlib==3.9.3
|
|
|
|
5 |
torch==2.4.0
|
6 |
pydantic==2.9.2
|
7 |
scikit-learn==1.5.2
|
8 |
+
matplotlib==3.9.3
|
9 |
+
gradio==5.7.1
|