Spaces:
Runtime error
Runtime error
Commit
·
6f32cf9
1
Parent(s):
fa34d81
Validating if cache file exist or not and accordingly runs caching.
Browse files
app.py
CHANGED
@@ -1,9 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
|
|
4 |
from sentence_transformers import SentenceTransformer
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
|
9 |
def image_to_embedding(img: np.ndarray = None, txt: str = None) -> np.ndarray:
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
+
from pathlib import Path
|
5 |
from sentence_transformers import SentenceTransformer
|
6 |
|
7 |
+
cache_path = Path('/app/cache')
|
8 |
+
|
9 |
+
if cache_path.exists():
|
10 |
+
print('Cache folder exists, loading from cache')
|
11 |
+
model = SentenceTransformer('clip-ViT-B-32', cache_folder=cache_path)
|
12 |
+
else:
|
13 |
+
print('Cache folder does not exist, loading from web')
|
14 |
+
model = SentenceTransformer('clip-ViT-B-32')
|
15 |
|
16 |
|
17 |
def image_to_embedding(img: np.ndarray = None, txt: str = None) -> np.ndarray:
|