Commit
·
e95d03f
1
Parent(s):
c84fd87
deploy
Browse files- services/embedding.py +7 -9
services/embedding.py
CHANGED
@@ -5,18 +5,16 @@ from typing import List, Optional
|
|
5 |
import torch
|
6 |
import os
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
os.environ["HF_HOME"] = "/app/cache"
|
11 |
-
os.environ["XDG_CACHE_HOME"] = "/app/cache" # Additional variable for broader compatibility
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
if not os.path.exists(cache_dir):
|
16 |
-
os.makedirs(cache_dir, exist_ok=True)
|
17 |
|
18 |
-
# Load model
|
19 |
model = SentenceTransformer("clip-ViT-B-32")
|
|
|
|
|
20 |
|
21 |
def get_text_embedding(text: str) -> Optional[List[float]]:
|
22 |
try:
|
|
|
5 |
import torch
|
6 |
import os
|
7 |
|
8 |
+
from huggingface_hub import HfFileSystem
|
9 |
+
import transformers.utils.hub
|
|
|
|
|
10 |
|
11 |
+
# Set cache directory globally for huggingface_hub
|
12 |
+
transformers.utils.hub.HUGGINGFACE_HUB_CACHE = "/app/cache/hub"
|
|
|
|
|
13 |
|
14 |
+
# Load model
|
15 |
model = SentenceTransformer("clip-ViT-B-32")
|
16 |
+
# Load model with custom cache directory
|
17 |
+
# model = SentenceTransformer("clip-ViT-B-32")
|
18 |
|
19 |
def get_text_embedding(text: str) -> Optional[List[float]]:
|
20 |
try:
|