Julien Matuszak commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,10 @@ import torch
|
|
| 5 |
import numpy as np
|
| 6 |
from gradio_client import Client
|
| 7 |
|
| 8 |
-
# Cache the model and tokenizer
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
def load_model_and_tokenizer():
|
| 11 |
model_name = "Frenchizer/all-MiniLM-L6-v2" # Replace with your Space and model path
|
| 12 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
@@ -32,7 +34,7 @@ labels = [
|
|
| 32 |
"sustained", "technical", "theater", "tourism", "travel"
|
| 33 |
]
|
| 34 |
|
| 35 |
-
@
|
| 36 |
def precompute_label_embeddings():
|
| 37 |
def encode_text(texts):
|
| 38 |
inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="pt")
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
from gradio_client import Client
|
| 7 |
|
| 8 |
+
# Cache the model and tokenizer using lru_cache
|
| 9 |
+
from functools import lru_cache
|
| 10 |
+
|
| 11 |
+
@lru_cache(maxsize=1)
|
| 12 |
def load_model_and_tokenizer():
|
| 13 |
model_name = "Frenchizer/all-MiniLM-L6-v2" # Replace with your Space and model path
|
| 14 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
|
| 34 |
"sustained", "technical", "theater", "tourism", "travel"
|
| 35 |
]
|
| 36 |
|
| 37 |
+
@lru_cache(maxsize=1)
|
| 38 |
def precompute_label_embeddings():
|
| 39 |
def encode_text(texts):
|
| 40 |
inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="pt")
|