Frenchizer commited on
Commit
e7dcd52
·
verified ·
1 Parent(s): 3f40561

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
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
- @gr.cache()
 
 
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
- @gr.cache()
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")